请教HttpURLConnection的返回码问题

发现有些跳转的网址,用jdk的HttpURLConnection类访问返回的响应不一样。比如http://dwz.cn/11ftOg这个链接:
java代码很简单:

        String requestUrl = "http://dwz.cn/11ftOg";
        HttpURLConnection conn = null;
        try {
            URL url = new URL(requestUrl);
            conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(300);
            conn.setReadTimeout(500);
            conn.setUseCaches(false);
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.connect();
            int code = conn.getResponseCode();
            System.out.println("+++++++ response code: " + code);
        } catch (IOException e) {
            System.out.println("+++++++ error:"+ e);
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

执行后输出:
+++++++

response code: 301

但是在浏览器访问抓包,在linux上curl访问都返回的是302:

~> curl -I 'http://dwz.cn/11ftOg'
HTTP/1.1 302 Found
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin,Accept,Content-Type,X-Requested-With
Access-Control-Allow-Methods: POST,GET,PUT,PATCH,DELETE,HEAD
Access-Control-Allow-Origin:
Content-Type: text/html; charset=utf-8
Date: Tue, 18 Dec 2018 07:32:23 GMT
Location: http://www.hzins.com/study/studytag/word-2820-205-9.html/?id=hz6
Set-Cookie: DWZID=71abaaa6daf9c9151434309799aacd30; Path=/; Domain=dwz.cn; Max-Age=31536000; HttpOnly

哪位大神讲讲这是啥原因呢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
请教高手HTTPURLConnection的问题
如果网站需要保持一个session,则必须在客户端写Cookie。而HTTPURLConnection好像无法保存Cookie。因此网页也获取不到了。因为我没有发过去客户端的cookie值。所以没有权限。rn请问大侠,怎么办。rn
请教HttpUrlConnection上传文件问题
已经加了rn代码:地址有效,执行到DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());时抛出异常,不知道怎么回事?rnjava.io.IOExceptionrn public void onFileItemClick(String filename)rn rn String uploadUrl = "http://192.168.1.103:8080/uhonesty/uploadFile";rn String end = "\r\n";rn String twoHyphens = "--"; // 两个连字符rn String boundary = "******"; // 分界符的字符串rn tryrn rn URL url = new URL(uploadUrl);rn HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();rn httpURLConnection.setDoInput(true);rn httpURLConnection.setDoOutput(true);rn httpURLConnection.setUseCaches(false);rn httpURLConnection.setRequestMethod("POST");rn // 设置Http请求头rn httpURLConnection.setRequestProperty("Connection", "Keep-Alive");rn httpURLConnection.setRequestProperty("Charset", "UTF-8");rn // 必须在Content-Type 请求头中指定分界符中的任意字符串rn httpURLConnection.setRequestProperty("Content-Type","multipart/form-data;boundary=" + boundary);rn rn //定义数据写入流,准备上传文件rn DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());//此处抛出异常,java.io.IOExceptionrn dos.writeBytes(twoHyphens + boundary + end);rn //设置与上传文件相关的信息rn dos.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\""rn + filename.substring(filename.lastIndexOf("/") + 1)rn + "\"" + end);rn dos.writeBytes(end);rnrn FileInputStream fis = new FileInputStream(filename);rn byte[] buffer = new byte[8192]; // 8krn int count = 0;rn // 读取文件夹内容,并写入OutputStream对象rn while ((count = fis.read(buffer)) != -1)rn rn dos.write(buffer, 0, count);rn rn fis.close();rn dos.writeBytes(end);rn dos.writeBytes(twoHyphens + boundary + twoHyphens + end);rn dos.flush();rn // 开始读取从服务器传过来的信息rn InputStream is = httpURLConnection.getInputStream();rn InputStreamReader isr = new InputStreamReader(is, "utf-8");rn BufferedReader br = new BufferedReader(isr);rn String result = br.readLine();rnrn Toast.makeText(this, result, Toast.LENGTH_LONG).show();rn dos.close();rn is.close();rn rn catch (Exception e)rn rn setTitle(e.getMessage());rn rn
返回码的问题
今天有个问题,我的项目需要访问其他服务器上的action,通过以下方法rncreateXMLHttp();rnxmlHttp.open("POST","http://.......");rnxmlHttp.onreadystatechange=yycxCallBack;rnxmlHttp.send(null);rn得到的返回码是0,这是为什么,有什么解决办法,求解答
spcomm 返回码的问题
纸币器(nv10)的com通信返回码错误:rn发送指令没有错误,可是偶数行的指令返回码只有'7f'rnrn正确的应是rnrn7f 80 ..........(发送)rn7f 80 ..........(返回)rnrn7f 00 ..........rn7f 00 ..........rnrn7f 80 ..........rn7f 80 ..........rnrn7f 00 ..........rn7f 00 ..........rn可现在是rn7f 80 ..........rn7f 80 ..........rnrn7f 00 ..........rn7f rnrn7f 80 ..........rn7f 80 ..........rnrn7f 00 ..........rn7f
httpurlconnection post请求获取返回码为400的异常信息
[img=https://img-bbs.csdn.net/upload/201805/07/1525660530_719256.png][/img]rn原curl请求是这样,会返回400,在java里使用httpurlconnection实现获取400的错误信息时报异常,如下图,该怎么做?[img=https://img-bbs.csdn.net/upload/201805/07/1525660697_250743.png][/img]rnrn代码如下:rntry rn SSLContext sslContext=SSLContext.getInstance("SSL");rn TrustManager[] tm=new MyX509TrustManager();rn MyX509TrustManager.trustAllHttpsCertificates();rn HttpsURLConnection.setDefaultHostnameVerifier(hv);rn sslContext.init(null, tm, new java.security.SecureRandom());rn URL url = new URL(baseurl+httpurl);rn connection = (HttpURLConnection) url.openConnection();rn connection.setRequestMethod("POST");rn connection.setDoInput(true);rn // 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。rn // 设置请求头部信息rn connection.setRequestProperty("xxx", "xxx");rn connection.setRequestProperty("xxx", "xxx");rn os = connection.getOutputStream();rn os.write(param.getBytes());rn System.out.println(connection.getResponseCode());rn is = connection.getInputStream();rn br = new BufferedReader(new InputStreamReader(is, "UTF-8"));rn StringBuffer sbf = new StringBuffer();rn String temp = null;rn // 循环遍历一行一行读取数据rn while ((temp = br.readLine()) != null) rn sbf.append(temp);rn sbf.append("\r\n");rn rn result = sbf.toString();rn rn rn catch (MalformedURLException e) rn e.printStackTrace();rn catch (IOException e) rn e.printStackTrace();rn catch (NoSuchAlgorithmException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (Exception e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn finally rn // 关闭资源rn if (null != br) rn try rn br.close();rn catch (IOException e) rn e.printStackTrace();rn rn rn if (null != os) rn try rn os.close();rn catch (IOException e) rn e.printStackTrace();rn rn rn if (null != is) rn try rn is.close();rn catch (IOException e) rn e.printStackTrace();rn rn rn // 断开与远程地址url的连接rn connection.disconnect();rn rn return result;rn rn请各位帮忙指点下,谢谢
新手求助!HttpURLConnection有时返回乱码的问题!
新手刚开始学习Java,弄个Get方式获取网页源码的代码,尝试获取Baidu首页的源码rn但是这里问题就来了,不停地多次运行(期间什么都不改变),有时候返回的数据就是好的,有时候返回的就是乱码,这是为啥????rn求大神解释!!!!!rn代码很简单:rn[code=java]tryrn rn url = new URL("http://www.baidu.com");rn HttpURLConnection httpURLConnection = (HttpURLConnection) urlrn .openConnection();rn httpURLConnection.setRequestMethod("GET");rn httpURLConnection.setReadTimeout(5000);rn InputStream inputStream = httpURLConnection.getInputStream();rn InputStreamReader inputStreamReader = new InputStreamReader(rn inputStream, "utf-8");rn BufferedReader bufferedReader = new BufferedReader(rn inputStreamReader);rn StringBuffer strBuffer = new StringBuffer();rn String line=null;rn while((line=bufferedReader.readLine())!=null)rn strBuffer.append("\n" + line);rn rn System.out.println(strBuffer);rn bufferedReader.close();rn catch (MalformedURLException e)rn rn e.printStackTrace();rn catch (IOException e)rn rn e.printStackTrace();rn [/code]rnrn在网上搜索的很多,可是都是编码问题,改了编码就好了,但是我这个重点是:rn有时候正常,有时候就乱码。。。rn乱码还复制不出来,真是醉了rn还是用过百度到的类似代码,也是有时好有时坏。。。rn
请教HttpURLConnection使用!
我在一个webpage中定义一个HttpURLConnection,那么在我的响应page中应该怎么定义rn呢? 谢谢!
关于xmlHttp.readyState的返回码的问题
按照网上教程写的rn[code=HTML]rn [/code]rnrn测试的时候 alert("Server is done!");一直没有响应,在updatePage第一行添加alertxmlHttp.readyState);后跳的窗口显示是1,怎么回事?rn
HttpURLConnection的问题
很奇怪的一个问题rn    String sTmp="http://0707yuan.china-manufacturers.org/Inquiry.html";rn try rn URL url=new URL(sTmp);rn rn       HttpURLConnection connect =(HttpURLConnection) url.openConnection();rn connect.setDoInput(true);rn rn BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));rn rn String line = null;rn StringBuffer content= new StringBuffer();rn rn while((line = in.readLine()) != null)//line为返回值,这就可以判断是否成功、rn rn content.append(line);rn rn rn in.close() ;rn in=null;rn url=null;rn String msg = content.toString();rn System.err.println(msg);rn rn catch(IOException ex)rn ex.printStackTrace();rn catch(Exception e)rn rn System.out.println("错误:");rn System.out.println(e.getStackTrace());rn rn rn rn rnrn为什么在ie中可以打开,在这里却得不到它的输出值呢?
HttpURLConnection的问题,
[size=16px]各位大侠:rn rn 我在进行URL连接的时候,定义了一个函数:static String getInfo(String urlPath) 参数为输入的网址,rnrn 但是奇怪的是我传进一个网址获取的网页内容为空,而当我在函数中指定URL时,却可以获取到内容。我比较了一下rnrn 两次HttpURLConnection对象,其中connection字段值在传参的时候为null,。而在函数中指定一个URL是有值的。rnrnrn说明一下,我的函数功能就是获取网页内容,有没有人遇到此种情况?望不吝赐教。[/size]
HttpURLConnection问题
URL l_url = new URL("http://www.google.com"); rn rn HttpURLConnection l_connection = (HttpURLConnection) l_url.openConnection(); rn l_connection.connect(); rnconnect失败 rn该如何夹代理 我的机器不能出国要叫代理
HttpURLConnection 的问题
代码运行到 connection.connect();会报networkonmainthreadexceptionrnURL postUrl = new URL("http://221.214.177.85/bb2/android_login.aspx?name=123&pwd=123");rn HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();rn connection.setDoInput(true);rn connection.setRequestMethod("GET");rn connection.setUseCaches(false);rn connection.setInstanceFollowRedirects(true);rn connection.setRequestProperty("Content-Type","text/xml");rn connection.connect();rn网址http://221.214.177.85/bb2/android_login.aspx?name=123&pwd=123返回的内容如下:rnrnrnfalsern用户名或密码不正确!rnrnrnAVD里面的target是:Android 4.0 -API Level14
请教ASCII码问题
各位rn我从串口读入的是gps信息,(我认为是ASCII码),但是输出的是乱码,我认为rn是不是因为vc是 UNCODE码 ,所以才是乱码,不知道这么理解对吗?rnrn若是这样,如何能把uncode转换成ascii码?
请教BCD码问题???
我记得BCD码就是Binary Coded Decimal,即“用二进制表示的十进制编码”,如8421BCD码,2421BCD码等。它应该只能表示数字啊,怎么可能表示字符呢?rn这个BCD码是网关生成的通过socket通讯过来的,按照协议是10位长的C-Octet String类型,难道我理解错了??rn
【100分】请教HttpURLConnection的连接问题
[code=Java]rnprotected static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)"rn + " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0"rn + " Mobile/7A341 Safari/528.16";rnrnHttpURLConnection uc = createHttpURLConnection(url);rnuc.setRequestProperty("user-agent", IPHONE_USERAGENT);rnuc.connect() //该操作需要20秒 ????????rn//创建Http连接rn public synchronized static HttpURLConnection createHttpURLConnection(URL url) rn HttpURLConnection uc = null;rn tryrn if (netType == NetType.CMWAP) // cmwap 上网模式, 使用代理rn Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,rn new InetSocketAddress(PROXY_SERVER, 80));rn uc = (HttpURLConnection) url.openConnection(proxy);rnrn[/code]rnrnuc.connect() //该操作需要20秒 ????????rn麻烦大家帮我看看这个问题吧? rn测试环境 移动卡 cmwap 连接 rn信号还可以。
安卓新手,请教关于httpUrlConnection网络请求的问题
[code=java]public interface IHttpCallback rnrn void onResponse(final String result);rnrn void onResponse(Bitmap bitmap);rnrn void onError(final String result);rn[/code]rnrn这是我写的一个获取数据的接口,其中有两个response方法,一个获取文字数据,一个获取图片数据,请问如何优化成只用一个response实现?
新手初学httpURLconnection 问题请教[50分]
这是代码,目标是点击按钮后get网页的HTML代码并显示在textview上,方便起见把主代码写在了主activityrn问题在于,为什么点了按钮没有任何反应?rn[code=java]package com.blankshrimp.httptest;rnrnimport android.support.v7.app.AppCompatActivity;rnimport android.os.Bundle;rnimport android.view.View;rnimport android.widget.Button;rnimport android.widget.TextView;rnrnimport java.io.BufferedReader;rnimport java.io.IOException;rnimport java.io.InputStream;rnimport java.io.InputStreamReader;rnimport java.net.HttpURLConnection;rnimport java.net.URL;rnrnpublic class MainActivity extends AppCompatActivity implements View.OnClickListener rnrn TextView resText;rnrn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn Button button1 = (Button) findViewById(R.id.button_233);rn resText = (TextView) findViewById(R.id.textview);rn button1.setOnClickListener(this);rn rnrn @Overridern public void onClick(View v) rn if (v.getId() == R.id.button_233) rn SRWHUC();rn rn rnrn private void SRWHUC() rn new Thread(new Runnable() rn @Overridern public void run() rn HttpURLConnection connection = null;rn BufferedReader reader = null;rn try rn URL url = new URL("http://www.baidu.com");rn connection = (HttpURLConnection) url.openConnection();rn connection.setRequestMethod("GET");rn connection.setConnectTimeout(8000);rn connection.setReadTimeout(8000);rn InputStream in = connection.getInputStream();rn reader = new BufferedReader(new InputStreamReader(in));rn StringBuilder response = (new StringBuilder());rn String line;rn while ((line = reader.readLine()) != null) rn response.append(line);rn rn showRes(response.toString());rn catch (Exception e) rn e.printStackTrace();rn finally rn if (reader != null) rn try rn reader.close();rn catch (IOException e) rn e.printStackTrace();rn rn rn if (connection != null) rn connection.disconnect();rn rn rn rn ).start();rn rnrn private void showRes (final String response) rn runOnUiThread(new Runnable() rn @Overridern public void run() rn resText.setText(response);rn rn );rn rnrn[/code]rnrn
请教一个BCD码(8421码)的问题
最近公司的一个项目,需要与上层平台进行通信.rn上层平台给我们分配了一个编号是A0089rn他们说这是一个BCD码.[color=#FF0000]需要把A转换为10[/color],看得我云里雾里的.rn请教一下它的内存布局是怎样的.rnrnrn0x0A, 0x00, 0x00, 0x08, 0x09rn0x00, 0x00, 0x0A, 0x00,0x89rnrn经测试两种都不对.
请教各位大侠Android中HttpURLConnection的问题
[code=Java]rn HttpURLConnection conn = null;rn URL url;rn try rn url = new URL("http://192.168.1.100/androidws/a.xml");rn conn = (HttpURLConnection)url.openConnection();rn int fileSize = conn.getContentLength();rn ...rn[/code]rn如上面的代码,当代码执行到int fileSize = conn.getContentLength();的时候,接着按F6单补调试,始终停留在这行代码,不能继续执行,请问各位大虾是怎么回事。
HttpurlConnection
在正在对HttpurlConnection进行了解,一直在使用公司的一个框架。一天到晚也就这么用,还真没想过它到底是怎么搞的。网上找了写说法,感觉都不怎么好,请各位给指点一下?
Httpurlconnection
代码包含了httpurlconnection基本操作,一些正常的操作。
HttpURLConnection
利用HttpURLConnection通过用户传入的参数来链接到在用户所需的网址,如果是多个不同的用户同时访问该方法时,会不会有个别用户的信息会被其他的用户传入信息所替代了?
HttpURLConnection文件下载\httpURLConnection文件下载
HttpURLConnection文件下载\httpURLConnection文件下载
SQL返回码详解
sql 返回码大全<br>查找挺方便
返回码和相应的查询条件
# 信息性状态码 100: ('continue',), 101: ('switching_protocols',), 102: ('processing',), 103: ('checkpoint',), 122: ('uri_too_long', 'request_uri_too_long'), # 成功状态码 200: ('ok', 'okay', 'all_ok', 'all_okay...
接口返回码处理
一般错误信息会以错误码的方式返回,而我们页面显示可能需要显示具体的错误信息,这样的话我们不妨将错误信息依键值对的方式存放, 错误码作为key,错误信息作为value。使用的时候通过错误码获取错误信息返回就行了 Map方式: public class ErrorCodeConstant { public static Map&lt;Integer, String&gt; errcodem...
DB2CODE返回码
This edition applies to Version 7 of IBM DATABASE 2 Universal Database Server for OS/390 and z/OS (DB2 for OS/390 and z/OS), 5675-DB2, and to any subsequent releases until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. This softcopy version is based on the printed edition of the book and includes the changes indicated in the printed version by vertical bars. Additional changes made to this softcopy version of the book since the hardcopy book was published are indicated by the hash (#) symbol in the left-hand margin. Editorial changes that have no technical significance are not noted. This and other books in the DB2 for OS/390 and z/OS library are periodically updated with technical changes. These updates are made available to licensees of the product on CD-ROM and on the Web (currently at www.ibm.com/software/data/db2/os390/library.html). Check these resources to ensure that you are using the most current information.
错误返回码
1、特别说明: 系统出现异常时,Fikker 会在浏览器上显示对应的错误提示页面,举例如下: 2、400 Bad Request: 400 Bad Request - Invalid Host (a)、非法域名请求,【主机管理】中无此域名/源站的相关配置。&amp;lt;如何自定义 400 Bad Request - Invalid Host 错误页面&amp;gt; (b)、请求 HTTP...
http返回码401
查看得知:401 - 未授权: 由于凭据无效,访问被拒绝。 代码其中一块需要读写文件,已经去掉只读,然后授权iis_users读写,解决问题。
app返回码说明
返回码 说明 公共码 10001 系统错误 10002 请求成功 10003 输入参数规则错误 10004 不存在的AppID,请检查AppID的正确性 10005 无效的数据ID,请检查传入的参数 10006
微信返回码详解
自己在开发微信公众号的过程中,遇到的,顺手搜集起来,供需要的人查看
phpcurl获取返回码
$ch = curl_init(); $user_agent = "Mozilla/4.0 "; curl_setopt($ch,CURLOPT_URL,'http://www.baidu.com'); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT
返回码查询器setup.exe
用于查询mainframe编程过程中的返回值意思,返回码查询器setup.exe
[前端]http返回码
http返回码是什么
db2错误返回码
该文档记录了操作db2数据库时错误返回码代码,sql语句执行后的返回码,便于开发者排查问题
网络请求返回码
全部的网络返回码,有具体的错误指明,欢迎下载~
wosa 错误返回码
主要是用来配合驱动进行查询用的,对于从事ATM测试行业和开发的用处还是有点点的。
HTTP 返回码详细介绍
HTTP 返回码 详细说明 对于想了解HTTP的朋友非常适用
update 失败的返回码?
在Oracle中执行一条update语句,如果符合where条件的数据不存在,会有一个特定的错误码返回吗?
DB2 返回码
DB2 返回码 -805 -911 -803 等各种返回码的意思
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法