我曾经得到以下对 php 请求的响应
响应:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
我的代码:
URL url = new URL("http://myappdemo.com/payumoney/payUmoneyHashGenerator.php");
// get the payuConfig first
String postParam = postParams[0];
byte[] postParamsByte = postParam.getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setInstanceFollowRedirects(false);
conn.setRequestProperty("Content-Length",
String.valueOf(postParamsByte.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postParamsByte);
InputStream responseInputStream = conn.getInputStream();
StringBuffer responseStringBuffer = new StringBuffer();
byte[] byteContainer = new byte[1024];
for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) {
responseStringBuffer.append(new String(byteContainer, 0, i));
}
Log.e("tag", "doInBackground: "+ responseStringBuffer.toString());
也试过 Volley 响应是
BasicNetwork.performRequest: Unexpected response code 301 for http://myappdemo.com/payumoney/payUmoneyHashGenerator.php
.
请帮帮我。 提前致谢。
最佳答案
301 Moved Permanently
用于永久 URL 重定向。应更新使用收到响应的 URL 的当前链接。尝试在您的链接中使用 https://
使用 URL url = new URL("https://myappdemo.com/payumoney/payUmoneyHashGenerator.php");
关于android - 响应 301 永久移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48167467/