2011-07-26 104 views
1

在我的應用程序。我必須使用HTTPPost方法註冊一個新用戶。我爲此寫了下面的代碼。但是,所有的時間,我得到像下面的迴應:HTTPPost參數發送問題

代碼:

String Category_url = "url"; 
try 
{ 
      SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss"); 
      f.setTimeZone(TimeZone.getTimeZone("UTC")); 

      String signature_string = "POST"+"users/register/"+"global.se"+String.valueOf(f.format(new Date())+" +0000"); 
      Log.d("signature_string", signature_string); 

      String auth_key = hmacSha1(signature_string, "1232132123213244353"); 
      Log.d("auth_key", auth_key); 

      HttpClient client = new DefaultHttpClient(); 
      HttpPost get = new HttpPost(Category_url); 


      List nvps = new ArrayList(); 
      nvps.add(new BasicNameValuePair("email", "[email protected]")); 
      nvps.add(new BasicNameValuePair("password", "123456")); 
      nvps.add(new BasicNameValuePair("first_name", "Mohit")); 
      nvps.add(new BasicNameValuePair("last_name", "Kanada")); 
      UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps,HTTP.UTF_8); 
      get.setEntity(p_entity); 




      get.addHeader("Host", "HOST_name"); 
      get.addHeader("X-SE-Date", String.valueOf(f.format(new Date()))+" +0000"); 
      get.addHeader("X-SE-Client", "client_name"); 
      get.addHeader("X-SE-Accept", "xml"); 
      get.addHeader("X-SE-Auth", auth_key); 

      HttpResponse httpresponse = client.execute(get); 
      HttpEntity httpentity = httpresponse.getEntity(); 
      String s = EntityUtils.toString(httpentity); 
      Log.d("login response", s); 
     } 
     catch (Exception e) 
     { 
     } 

響應:

<?xml version="1.0" encoding="UTF-8"?> 
<error> 
<code>InvalidParameter</code> 
<message>Invalid parameter specified (email)</message> 
</error> 
</xml> 

如果我不傳遞任何參數,那麼我也得到同樣的答覆。使用這個參數,我可以使用瀏覽器在線註冊新用戶。

我認爲web服務器無法獲取我的參數,因爲參數名稱的任何變化都不會影響響應。

+0

你能告訴我有多少參數需要你的網址是什麼? –

+0

url需要四個參數,我通過這四個參數。 –

+0

你可以發佈你的網址嗎? –

回答

0

圖書館使用:http://loopj.com/android-async-http/

private OnClickListener login = new OnClickListener() { 

public void onClick(View view) { 

AsyncHttpClient myClient = new AsyncHttpClient(); 
myClient.get(URL, null); 
myClient.setCookieStore(myCookieStore); 
myClient.setCookieStore(myCookieStore); 
String username = ""; 
String password = ""; 
RequestParams params1 = new RequestParams(); 
params1.put("username", username); 
params1.put("password", password); 
pd = ProgressDialog.show(this, "", "Signing In..."); 
myClient.post(URL, params1, 
     new AsyncHttpResponseHandler() { 
      @Override 
      public void onSuccess(String response) { 
       System.out.println("response" + response); 
       pd.dismiss(); 
       if (response.contains("<!--Authorized-->")) { 
       } 
       else { 
        pd.dismiss(); 
        Context mContext = SigninActivity.this; 
        notMatchDialog = new Dialog(mContext); 
        notMatchDialog.setContentView(R.layout.loginfaileddialoglayout); 
        notMatchDialog.setTitle("Login failed"); 
        dismissDialogButton = (Button) notMatchDialog.findViewById(R.id.dismissDialogButton); 
        dismissDialogButton.setOnClickListener(dismissDialog); 
        notMatchDialog.show(); 
       } 
      } 

      @Override 
      public void onFailure(Throwable e, String response) { 
       // TODO Need to figure out different failures and try to help the user. 
      } 
     }); 
} 
}; 
+0

請不要在問題中複製您的答案。如果問題是重複的,請留下評論指出其他問題(或者如果您有足夠的聲望,請將問題標記出來)。如果問題不同,請針對每個問題定製答案。 –

+0

我應該刪除它們嗎? –