android DefaultHttpClient POST服务wcf .svc

时间:2012-08-09 22:54:59

标签: java android iphone json

我有这个代码

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());
    }

我在IPHONE中发布并完美地工作:

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

当我也在ANDROID发布时。

Response return HTTP 1 400

示例:

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

但是,我发布了这个

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

这项工作只有在我使用“[]”时我才会有一些错误

抱歉我的英语:)

0 个答案:

没有答案