NutzCN Logo
问答 Http Get 请求 返回 301 Moved Permanentl 错误
发布于 1955天前 作者 科技 5126 次浏览 复制 上一个帖子 下一个帖子
标签:

测试地址

https://detail.m.1688.com/page/index.html?offerId=579379061481

返回 301 Moved Permanentl 错误,Http 有办法解除这个问题么

用以下代码测试是ok的

public static String post(String url, Map<String, String> headerMap) {
		CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
		try {
			HttpPost post = new HttpPost(url);
			// 请求头
			if (headerMap != null) {
				for (Map.Entry<String, String> entry : headerMap.entrySet()) {
					post.addHeader(entry.getKey(), entry.getValue());
				}
			}
			// 执行请求
			CloseableHttpResponse httpResponse = httpClient.execute(post);
			if (httpResponse.getStatusLine() == null || httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
				return "";
			}
			try {
				HttpEntity entity = httpResponse.getEntity();
				if (null != entity) {
					return EntityUtils.toString(entity);

				}
			} finally {
				httpResponse.close();
			}

		} catch (UnsupportedEncodingException e) {
			return "";
		} catch (IOException e) {
			return "";
		} finally {
			if (httpClient != null) {
				try {
					httpClient.close();
				} catch (IOException e) {
				}
			}
		}
		return "";
	}

header:

Map<String, String> header = Maps.newHashMap();
		header.put("authority", "herasecret.tmall.com");
		header.put("path", "/i/asynSearch.htm?_ksTS=1561616715096_120&callback=jsonp121&mid=w-15369382533-0&wid=15369382533&path=/category.htm&spm=a1z10.3-b-s.w4011-15369382533.1.298d1a07ePAiRG");
		header.put("scheme", "https");
		header.put("accept", "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01");
		header.put("accept-encoding", "gzip, deflate, br");
		header.put("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7");
		header.put("cookie",
				"cna=1zBgFM+OZTACAd3ZWxIS1GOx; hng=CN%7Czh-CN%7CCNY%7C156; UM_distinctid=16a7dc4b405a3a-03606c0d283702-37607603-13c680-16a7dc4b406875; tk_trace=1; t=51003c03135f3cf0eab949bdd148e5fa; _tb_token_=f6e7bbb361e69; cookie2=727ac0c5b9de0dce89760eb8fd250b07; _m_h5_tk=263c698bb3a4c54179b0e0e8212bd123_1561539760997; _m_h5_tk_enc=d8cb8452a273a2eb060dbb60ecd50d91; sm4=110100; csa=undefined; pnm_cku822=; dnk=simsimtoy; uc1=cookie16=W5iHLLyFPlMGbLDwA%2BdvAGZqLg%3D%3D&cookie21=W5iHLLyFfoWkRIw3&cookie15=VT5L2FSpMGV7TQ%3D%3D&existShop=false&pas=0&cookie14=UoTaGdugGfweBA%3D%3D&tag=8&lng=zh_CN; uc3=vt3=F8dBy34bZqkv6wevwQw%3D&id2=UNQxQivalWQHAw%3D%3D&nk2=EFed7iLdzs52&lg2=VT5L2FSpMGV7TQ%3D%3D; tracknick=simsimtoy; lid=simsimtoy; _l_g_=Ug%3D%3D; unb=3467742702; lgc=simsimtoy; cookie1=AVUvPxqi%2FYMzsr2sp6jDTmwf9k8Qd7ORroEbOMmldhc%3D; login=true; cookie17=UNQxQivalWQHAw%3D%3D; _nk_=simsimtoy; sg=y20; csg=3520bfb1; enc=IxmxSOwtoRsCwzoNZeIo%2BSAZc1WEtH2%2BpvYGsV38p6a59mOL5gKKJgS5p8FeU7o1lZbYXmjyDlf2%2Fub%2FB3MNlg%3D%3D; cq=ccp%3D0; l=bBLLkHqVvrmRMIpwBOCZZuI8YWQ9SIRAguPRwhjJi_5Bf6L6CaQOkYUWaFp6Vj5Rs-YB4i7e-P29-etXi; isg=BFBQDVqSOcdnpuMJTr393sJWIZhisTfcieFUP0ohFKt-hfAv8iid8ouzXQ3AVew7");
		header.put("referer", "https://herasecret.tmall.com/category.htm?spm=a1z10.3-b-s.w4011-15369382533.1.298d1a07ePAiRG,http://m.1688.com/offer/579379061481.html?offerId=579379061481");
		header.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36");
		header.put("x-requested-with", "XMLHttpRequest");
		header.put("Cache-Control", "no-cache");
		header.put("Postman-Token", "b064e9d3-9a99-4679-9d57-058802bb82f0,8c7809eb-170c-4c52-877c-37b31a798c71");
		header.put("Connection", "keep-alive");
		header.put("cache-control", "no-cache");
0 回复
添加回复
请先登陆
回到顶部