how to set request header for sending data from android apps to our server

后端 未结 4 1046
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 12:33

How to set http header to sending json object from our android apps what type of header we want to use for sending data from client side to server.why we ar

相关标签:
4条回答
  • 2020-12-30 12:51

    I coded a web services in .NET an then used ksoap2 in my android application to send data to my server.

    Look at ksoap2-android:

    http://simpligility.github.io/ksoap2-android/index.html

    I suggest to add this library:

    https://oss.sonatype.org/content/repositories/ksoap2-android-releases/com/google/code/ksoap2-android/ksoap2-android-assembly/3.0.0/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar

    that carries also all dependencies.

    0 讨论(0)
  • 2020-12-30 12:55

    you can look into this

    you can use this

    HttpPost post = new HttpPost( "http://wwww.testserver.com/userAddMoney" );
    
    post.addHeader( "X-Testing-Auth-Secret" , "kI7wGju76kjhJHGklk76" );
    
    0 讨论(0)
  • 2020-12-30 13:15

    you can use

    try {
                HttpClient client = new DefaultHttpClient();  
                String getURL = "http://helloworld.com/getmethod.aspx?id=1&method=getData";
                HttpGet httpGet = new HttpGet(getURL);
                **httpGet .setHeader("Content-Type", "application/x-zip");**
                HttpResponse response = client.execute(httpGet);  
                HttpEntity resEntity = response.getEntity();  
                if (resEntity != null) {  
                            //parse response.
                            Log.e("Response",EntityUtils.toString(resEntity));
                        }
        } catch (Exception e) {
            e.printStackTrace();
        }
    
    0 讨论(0)
  • 2020-12-30 13:15

    try this:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://floating-wildwood-1154.herokuapp.com/posts/create_a_post");
    
    // Add Headers
    httppost.addHeader("key1", "value1");
    httppost.addHeader("key2", "value2");
    
    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("content", valueIWantToSend));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    } catch (IOException e) {
    // TODO Auto-generated catch block
    }
    
    0 讨论(0)
提交回复
热议问题