Android JSON post to WCF Service

后端 未结 1 1015
遥遥无期
遥遥无期 2021-01-01 07:37

I having a problem with my android client trying to post a JSON class to my wcf service. Here is the code for android client :

    public HttpResponse TestP         


        
1条回答
  •  生来不讨喜
    2021-01-01 07:55

    The wrapping of the object (since you specified WebMessageBodyStyle.Wrapped) is done based on the parameter name, not the parameter type. The name of the outermost JSON member should be "tm", not "TestModel":

    public HttpResponse TestPost() throws Exception  
    { 
        HttpPost httpost = new HttpPost(url+"/TestPost"); 
    
        JSONStringer img = new JSONStringer() 
            .object() 
            .key("tm") 
                .object() 
                    .key("p1").value("test") 
                    .key("p2").value("test") 
                    .key("p3").value(1) 
                    .key("p4").value("test") 
                    .key("p5").value(2) 
                    .key("p6").value("test;test") 
                .endObject() 
            .endObject(); 
            StringEntity se = new StringEntity(img.toString()); 
    
        httpost.setEntity(se); 
    
        httpost.setHeader("Accept", "application/json"); 
        httpost.setHeader("Content-type", "application/json"); 
    
        return httpclient.execute(httpost); 
    } 
    

    0 讨论(0)
提交回复
热议问题