3
我使用parse.com的REST API爲我的登錄系統(API:https://parse.com/docs/rest#users-signup)。HTTP郵政工作,但GET不工作
的問題是當寄存器工作:
JSONObject json = new JSONObject();
json.put("username", username);
json.put("password", password);
json.put("email", email);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Reference.PARSE_API_URL
+ Reference.PARSE_API_USERS);
httppost.addHeader("X-Parse-Application-Id", Reference.APP_ID);
httppost.addHeader("X-Parse-REST-API-Key", Reference.REST_API_KEY);
httppost.addHeader("Content-Type", "application/json");
httppost.setEntity(new StringEntity(json.toString()));
HttpResponse httpresponse = httpclient.execute(httppost);
System.out.println(httpresponse.getStatusLine());
登錄系統犯規(是的,我對數據進行加密的網站說):
JSONObject jsonadd = new JSONObject();
jsonadd.put("username", username);
jsonadd.put("password", password);
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(Reference.PARSE_API_URL + Reference.PARSE_API_LOGIN + "?" + URLEncoder.encode(jsonadd.toString(), "UTF-8"));
httpget.addHeader("X-Parse-Application-Id", Reference.APP_ID);
httpget.addHeader("X-Parse-REST-API-Key", Reference.REST_API_KEY);
HttpResponse httpresponse = httpclient.execute(httpget);
System.out.println(httpresponse.getStatusLine());
而且這些都是引用變量:
public static final String APP_ID = "(HIDDEN)";
public static final String REST_API_KEY = (HIDDEN)";
public static final String VERSION_CLASS_NAME = "version";
public static final String PARSE_API_URL = "https://api.parse.com";
public static final String PARSE_API_URL_CLASSES = "/1/classes/";
public static final String PARSE_API_USERS = "/1/users";
public static final String PARSE_API_LOGIN = "/1/login";
錯誤: HTTP/1.1 400錯誤請求