向Android http post添加多个标题

向Android http post添加多个标题,android,http-post,Android,Http Post,我需要提出一个带有两个标题的post请求,我按照 post.setHeader("DataServicesKey", sDataServicesKey); post.setHeader("SiteKey", "keySite"); 这不起作用,我得到了响应null,但是如果我省略了第二个标题,我会得到错误缺少站点密钥,我也尝试了addHeader关于如何设置多个标题的任何建议步骤1:添加到JsonObject: JSONArray mJSONArray = new JSONAr

我需要提出一个带有两个标题的post请求,我按照

post.setHeader("DataServicesKey", sDataServicesKey);
        post.setHeader("SiteKey", "keySite");

这不起作用,我得到了响应
null
,但是如果我省略了第二个标题,我会得到错误
缺少站点密钥
,我也尝试了
addHeader
关于如何设置多个标题的任何建议步骤1:添加到JsonObject:

JSONArray mJSONArray = new JSONArray(selectedSubmit);
            JSONObject JSONSend = new JSONObject();
            JSONArray mJSONArray1 = new JSONArray(anserSubmit);

            try {
                JSONSend.put("Items", mJSONArray);
                JSONSend.put("Items1", mJSONArray1);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            }
            postData(
                    "url.php",
                    JSONSend);
步骤2:在此方法中将jsonObject发布到标题:


将您的输出编码为json…在json对象中,您可以添加多个字段,将json对象添加到headerI也可以不使用这种方法设置实体,我需要发送miltiple HeaderOK,您可以告诉我如何从您的服务端scriptresp=mHttpClient.execute(post)读取数据;HttpEntity entityResponse=resp.getEntity();值=EntityUtils.toString(entityResponse);我的意思是你使用的是php还是.net?
public void postData(String url, JSONObject obj) {
        // Create a new HttpClient and Post Header



        HttpParams myParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);

        HttpClient httpclient = new DefaultHttpClient();
        String json = obj.toString();

        try {

            HttpPost httppost = new HttpPost(url.toString());
            httppost.setHeader("Content-type", "application/json");

            StringEntity se = new StringEntity(obj.toString());
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                    "application/json"));
            httppost.setEntity(se);
            System.out.println("here se is " + se);
            HttpResponse response = httpclient.execute(httppost);

            String temp = EntityUtils.toString(response.getEntity());
            System.out.println(url + "sample json response" + temp);
            Log.i("tag", temp);

        } catch (ClientProtocolException e) {

        } catch (IOException e) {
        }
    }