gpt4 book ai didi

java - HTTP Post 有效但 GET 无效

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:08 24 4
gpt4 key购买 nike

我正在为我的登录系统使用 parse.com 的 REST API(API:https://parse.com/docs/rest#users-signup)。

问题是注册工作时:

        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 错误请求

最佳答案

回答我自己的问题:

数据不需要编码,连接需要

HttpGet httpget = new HttpGet("https://api.parse.com/1/login?username="username"&password="password"");

(用户名和密码不带引号

关于java - HTTP Post 有效但 GET 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16582670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com