0
我需要通過發出發佈請求來驗證用戶。我張貼我的XML數據使用REST協議,但得到403錯誤。請幫助我找出我做錯了什麼,下面是我的代碼發佈。在android中,我發佈xml數據到服務器,但得到403錯誤
public void makePostConnection(String fileUrl,
HashMap<String, String> requestData) {
URL url;
HttpURLConnection urlConnection;
try {
url = new URL(fileUrl);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(fileUrl);
httppost.addHeader("accept", "text/xml");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
requestData.size());
System.out.println("Size= " + requestData.size());
for (Entry<String, String> entry : requestData.entrySet()) {
nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry
.getValue()));
System.out.println("Key= " + entry.getKey() + " Value= "
+ entry.getValue());
}
System.out.println("Request ba= " + nameValuePairs.toString());
StringEntity requestBody = new StringEntity(
nameValuePairs.toString());
// requestBody.setContentType("text/xml");
// httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setEntity(requestBody);
// httppost.set
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int code = response.getStatusLine().getStatusCode();
System.out.println("Code= " + code);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
403錯誤意味着它是一個身份驗證問題。服務器是否需要認證? – edwardmp
準確地說我的服務器需要一個認證令牌我得到它並使我的請求正文如下:[token = bEZ9C61PLg56yz81LM1yo9S,imeino = 12345676543456543234,[email protected],mobileno = 1447525863] –
檢查服務器是否足夠以驗證.. – edwardmp