android - 响应 301 永久移动

标签 android http

我曾经得到以下对 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/

相关文章:

android - 使用startActivityForResult()在 Activity 开始之前显示MainActivity的Android应用

http - 多个站点共享一个IP地址: I can't reach special site using Host header

http - Camel 从 http 到文件到我的文件系统

jquery - http.get 数据并从此数据更改 css Ionic 3

java - 可运行更改错误的单元格

java - Gradle 项目同步失败 - Android Studio Gradle Build 2.20

http - 没有错误,但Go应用仍然无法正常运行

Objective-C:将选择器作为参数传递然后调用它

android - 用于显示可滚动多行文本的最佳 Android 控件

android - 编译渲染脚本错误 "llvm-rs-cc finished with non-zero exit value 127"