Android DefaultHttpClient POST for serving wcf.svc

I hava this code

public static String methodPost(final String url, final String dataToPost) throws ClientProtocolException,
        IOException, IllegalStateException, Exception {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        StringEntity se = new StringEntity(dataToPost);
        se.setContentEncoding("UTF-8");
        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httpPost.setEntity(se);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        return streamToString(httpEntity.getContent());
    }

I host this on IPHONE and work fine:

@"{\"var1\":\"Value1\"}{\"var2\":[{\"item1\":\"1\"},{\"item1\":\"Value2\"}]}"

when I send a message also to ANDROID.

Response return HTTP 1 400

example:

methodPost(url, "{\"var1\":\"Value1\"}{\"var2\":[{\"item1\":\"1\"},{\"item1\":\"Value2\"}]}");

but, I publish it

methodPost(url, "{\"var1\":\"Value1\"}{\"var2\":\"Value2\"}");

this only works fine when I use "[]" I have some error

sorry for my English:)

0
source share

Source: https://habr.com/ru/post/1749577/


All Articles