2010-10-21 133 views

回答

3

以下是設置請求頭的例子

HttpPost post = new HttpPost("someurl"); 

    post.addHeader(key1, value1)); 
    post.addHeader(key2, value2)); 
2

下面是一個Basic Access Authentication代碼:

HttpPost request = new HttpPost("http://example.com/auth"); 
request.addHeader("Authorization", "Basic ThisIsJustAnExample"); 

然後就是如何執行的例子它:

HttpParams httpParams = new BasicHttpParams(); 
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); 
HttpConnectionParams.setConnectionTimeout(httpParams, 3000); 
HttpClient httpclient = null; 
httpclient = new DefaultHttpClient(httpParams); 

HttpResponse response = httpclient.execute(request); 

Log.d("Log------------", "Status Code: " + response.getStatusLine().getStatusCode()); 
相關問題