本地服务的 GET 请求的意外响应代码 307
Unexpected response code 307 for GET request for local service
我正在尝试连接到我在 .net core 2.0 中编写的本地主机 Web 服务。使用模拟器的浏览器,我能够调用它并取回 JSON 数据。但是,在我的应用程序中,当我尝试获取它时,我收到了响应代码 307。
public void onClick(View view)
{
String url = String.format("http://10.0.2.2:5000/api/testservice/tickerpnl?ticker=%s&purchaseDate=%s&shares=%s/"
, tickerText.getText().toString(), dateText.getText().toString(), sharesText.getText().toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try
{
double pnl = response.getDouble("PNL");
} catch (JSONException e)
{
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
requestQueue.add(jsonObjectRequest);
}
在堆栈跟踪中,我得到以下信息:
D/NetworkSecurityConfig:未指定网络安全配置,使用平台默认设置
E/Volley:[403] BasicNetwork.performRequest:http://10.0.2.2:5000/api/testservice/tickerpnl?ticker=AAPL&purchaseDate=1-1-15&shares=1
的意外响应代码 307
再次使用来自堆栈跟踪的 link 我能够将 JSON 数据取回,只需将其粘贴到模拟器的浏览器中即可,但不知何故,使用 JsonObjectRequest 无法正常工作。
请求队列初始化为
private RequestQueue requestQueue;
requestQueue = Volley.newRequestQueue(this);
我发现问题是,对于 .net 核心,我有将 http 重定向到 https 的代码,所以这就是我收到 307 错误的原因,因为我试图使用 http
调用它
我正在尝试连接到我在 .net core 2.0 中编写的本地主机 Web 服务。使用模拟器的浏览器,我能够调用它并取回 JSON 数据。但是,在我的应用程序中,当我尝试获取它时,我收到了响应代码 307。
public void onClick(View view)
{
String url = String.format("http://10.0.2.2:5000/api/testservice/tickerpnl?ticker=%s&purchaseDate=%s&shares=%s/"
, tickerText.getText().toString(), dateText.getText().toString(), sharesText.getText().toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try
{
double pnl = response.getDouble("PNL");
} catch (JSONException e)
{
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
requestQueue.add(jsonObjectRequest);
}
在堆栈跟踪中,我得到以下信息:
D/NetworkSecurityConfig:未指定网络安全配置,使用平台默认设置 E/Volley:[403] BasicNetwork.performRequest:http://10.0.2.2:5000/api/testservice/tickerpnl?ticker=AAPL&purchaseDate=1-1-15&shares=1
的意外响应代码 307再次使用来自堆栈跟踪的 link 我能够将 JSON 数据取回,只需将其粘贴到模拟器的浏览器中即可,但不知何故,使用 JsonObjectRequest 无法正常工作。
请求队列初始化为
private RequestQueue requestQueue;
requestQueue = Volley.newRequestQueue(this);
我发现问题是,对于 .net 核心,我有将 http 重定向到 https 的代码,所以这就是我收到 307 错误的原因,因为我试图使用 http
调用它