POST使用uploadstring方法调用web服务并传递json数组
我正在尝试向web服务发送帖子。我正在使用WebClient类并调用uploadstring方法。在我调用的web服务需要一些数据(特别是json数组)之前,这一切都可以正常工作。我试图找出数据需要的格式,以便web服务能够正确地接受和使用数据。例如:POST使用uploadstring方法调用web服务并传递json数组,json,post,webclient,uploadstring,Json,Post,Webclient,Uploadstring,我正在尝试向web服务发送帖子。我正在使用WebClient类并调用uploadstring方法。在我调用的web服务需要一些数据(特别是json数组)之前,这一切都可以正常工作。我试图找出数据需要的格式,以便web服务能够正确地接受和使用数据。例如: WebClient myWebClient = new WebClient(); string resp = myWebClient.UploadString("www.myUrl.com", "POST", "someDataToSend");
WebClient myWebClient = new WebClient();
string resp = myWebClient.UploadString("www.myUrl.com", "POST", "someDataToSend");
任何帮助都将不胜感激
正在调用的web服务(vb.net)采用keyvaluepair:
<OperationContract(), WebInvoke(BodyStyle:=WebMessageBodyStyle.WrappedRequest, Method:="POST", RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json)> _
Public Function DoSomething(ByVal myKeyValuePair() As KeyValuePair(Of String, String)) As String
_
公共函数DoSomething(ByVal myKeyValuePair()作为KeyValuePair(字符串的,字符串的))作为字符串
我找到了解决方案。数据必须采用json格式:
{“类型”:[{“键”:“cType”,“值”:“年龄”}]}
我创建了一个类,将其序列化,然后在中欺骗了方括号
Public Class cType
Private _key As String
Public Property Key() As String
Get
Return _key
End Get
Set(ByVal value As String)
value = "cType"
_key = value
End Set
End Property
Public value As String
End Class
Dim objType As cType = New cType
objType.value = "Age"
Dim myData As String = deserializer.Serialize(New With {.cType = objType})
myData = myData.Insert(12, "[")
myData = myData.Insert(myData.Length - 1, "]")