我在vb.net中创建了一个wcf服务。服务代码在这里:
<ServiceContract()>
Public Interface IServiceUpload
<OperationContract()> _
<WebInvoke(Method:="POST", BodyStyle:=WebMessageBodyStyle.Wrapped, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json,UriTemplate:="UploadFile")>
Function UploadFile(F As FileStructure) As String
<DataContract()> _
Class FileStructure
<DataMember()> _
Public Property gp1 As String
End Class
End Interface
我通过Android从此代码发送json数据:
JSONStringer UPJ = new JSONStringer();
try {
UPJ.object()
.key("F").object().key("gp1")
.value("50").endObject().endObject();
} catch (JSONException e) {
e.printStackTrace();
}
OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String upload=jsonObject2.toString();
writer.write(UPJ.toString());
我的问题是我在尝试阅读服务中的F.gp1时总是返回http错误400。我认为发送的json是null。帮帮我吧!