【发布时间】:2011-07-26 07:06:58
【问题描述】:
在我的应用程序中。我必须使用 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", "mohit.kanada@gmail.com"));
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>
如果我不传递任何参数,那么我也会得到相同的响应。使用此参数,我可以使用浏览器在线注册新用户。
我认为网络服务器无法获取我的参数,因为参数名称的任何更改都不会影响响应。
【问题讨论】:
-
你能告诉我你的url需要多少参数吗?
-
url 需要四个参数,我通过了所有四个参数。
-
你能把你的网址贴出来吗?
-
使用代码中显示的四个参数,我可以从 Web 服务器的浏览器客户端 api 注册用户
标签: android http parameters http-post