How to set a Http header to retrive a json Object

后端 未结 1 510
抹茶落季
抹茶落季 2021-01-07 14:30

Im trying to create a httpGet that returns a similar request as :

http://www.myserver.com/do.json?json={\"magazine\":\"-1\"}

I can\'t seem to get the header

相关标签:
1条回答
  • 2021-01-07 14:45
            HttpGet get;
            HttpParams httpParameters;
    try
                {
                    httpParameters = new BasicHttpParams();
                    String auth = android.util.Base64.encodeToString(
                            (username + ":" + userpwd).getBytes("UTF-8"), 
                            android.util.Base64.NO_WRAP
                        );
                        HttpGet request = new HttpGet(StaticURL.uMain+resourceURI);
    
                        request.addHeader("Authorization", "Basic "+ auth);
    
                    HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
                    client = new DefaultHttpClient(httpParameters);
    
                    response = client.execute(request);
                    userAuth = EntityUtils.toString(response.getEntity());
    
                    System.out.println("Data. in login.."+userAuth);
    
    
                }
    
                catch(Exception e)
                {
    
                    System.out.println("Error.."+e);
                }
    

    note: use Base64 api externally

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