Java 来自android客户端的Http响应代码400

Java 来自android客户端的Http响应代码400,java,android,wcf-data-services,Java,Android,Wcf Data Services,我从我的服务器获得以下响应代码: 07-05 10:55:20.478 24688-24804/com.example.phuluso.aafs I/System.out: Response 400 以下是我试图发布到我的WCF服务器的Json数据: { "Title":"Mrs", "Name":"Amber", "Surname":"Rose", "Email":"amber@gmail.com", "AuthenticationLevel":"S"

我从我的服务器获得以下响应代码:

07-05 10:55:20.478 24688-24804/com.example.phuluso.aafs I/System.out: Response 400
以下是我试图发布到我的
WCF服务器的
Json
数据:

{
    "Title":"Mrs",
    "Name":"Amber",
    "Surname":"Rose",
    "Email":"amber@gmail.com",
    "AuthenticationLevel":"S",
    "ContactNumber":"0820653887",
    "Password":"123",
    "Gender":"Female",
    "FundingType":"NSFAS",
    "CampusId":2,"StudentNumber":201431511
}
以下是我的android代码:

String jsonString = "";

try {
    JSONStringer jsonStringer = new JSONStringer()

    .object()
    .key("Title").value("Mrs")
    .key("Name").value("Amber")
    .key("Surname").value("Rose")
    .key("Email").value("amber@gmail.com")
    .key("AuthenticationLevel").value("S")
    .key("ContactNumber").value("0820653887")
    .key("Password").value("123")
    .key("Gender").value("Female")
    .key("FundingType").value("NSFAS")
    .key("CampusId").value(2)
    .key("StudentNumber").value(201431511)

    .endObject();

    jsonString = jsonStringer.toString();

} catch (JSONException e) {
    e.printStackTrace();
}

String http = "http://10.0.2.2:8750/WCF/UserRegistration.svc/registerStudentJson";

HttpURLConnection connection = null;
try {

    System.out.println("Connecting to server");
    URL url = new URL(http);
    connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Accept","application/json");
    connection.setRequestProperty("Content-Type","application/json");
    connection.setRequestProperty("charset", "UTF-8");
    connection.setRequestProperty("Content-Length","352");
    connection.setUseCaches(false);
    connection.setConnectTimeout(50000);
    connection.setReadTimeout(50000);

    connection.connect();

    System.out.println("Connected");

    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
               // out.write(studjason.toString());
    out.write(URLEncoder.encode(jsonString.toString(),"UTF-8"));
    out.flush();
    out.close();

    int result = connection.getResponseCode();

    System.out.println("Response" + " " + result);

               // System.out.println(studjason.toString());
    System.out.println(jsonString.toString());

} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (connection != null) {
        connection.disconnect();
    }
}

return null;
这是我的wcf代码:

[OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/registerStudentJson", ResponseFormat =
           WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,  BodyStyle = WebMessageBodyStyle.Wrapped)]
        void RegisterStudentJson(string student);
实施:

public void RegisterStudentJson(string student)
{
    JavaScriptSerializer oJS = new JavaScriptSerializer();
    Student studentObject = new Student();
    studentObject = oJS.Deserialize<Student>(student);
    RegisterStudent(studentObject);

}
公共无效注册表studentjson(字符串student)
{
JavaScriptSerializer oJS=新的JavaScriptSerializer();
Student studentObject=新学生();
studentObject=oJS.反序列化(学生);
注册学生(学生对象);
}

问题出在哪里?有什么问题吗?不知怎的,我收到了一个错误的请求响应(http响应代码400),不知道我在android客户端的连接上哪里出错了???352 ??? 硬编码不好。有什么问题吗?有什么问题吗?不知怎的,我收到了一个错误的请求响应(http响应代码400),不知道我在android客户端的连接上哪里出错了???352 ??? 糟糕的硬编码。