当前位置: 首页 > news >正文

老网站怎么做循环链接seo公司中国

老网站怎么做循环链接,seo公司中国,怎么登陆网站后台管理系统,有什么软件可以制作抽奖页面目录 使用GET方法#xff0c;访问GET接口#xff0c;服务端返回405使用GET方法#xff0c;访问POST接口#xff0c;服务端返回405使用POST方法#xff0c;访问GET接口#xff0c;服务端返回405 使用GET方法#xff0c;访问GET接口#xff0c;服务端返回405 发生场景访问GET接口服务端返回405使用GET方法访问POST接口服务端返回405使用POST方法访问GET接口服务端返回405 使用GET方法访问GET接口服务端返回405 发生场景 复制的POST请求代码手动修改为GET没有修改彻底导致错误。 错误代码 public class GET405 {public static void main(String[] args) {try {String defURL https://httpbin.org/get;URL url new URL(defURL);// 打开和URL之间的连接HttpURLConnection con (HttpURLConnection) url.openConnection();con.setRequestMethod(GET);//请求get方式con.setDoInput(true);// 默认值为 truecon.setDoOutput(true);//默认值为 false传body参数必须写// 得到请求的输出流对象OutputStreamWriter writer new OutputStreamWriter(con.getOutputStream(), UTF-8);String body usernamexiaohupassword123456;writer.write(body);writer.flush();// System.out.println(http请求方法:con.getRequestMethod());System.out.println(http状态码: con.getResponseCode());// 获取服务端响应通过输入流来读取URL的响应InputStream is con.getInputStream();BufferedReader reader new BufferedReader(new InputStreamReader(is, UTF-8));StringBuffer sbf new StringBuffer();String strRead null;while ((strRead reader.readLine()) ! null) {sbf.append(strRead);sbf.append(\r\n);}reader.close();// 关闭连接con.disconnect();// 打印读到的响应结果System.out.println(运行结束 sbf.toString());} catch (Exception e) {e.printStackTrace();}} }报错log: 405原因 con.getOutputStream() 会把原有的GET方法改为POST方法用POST方法访问GET接口就报错405。看jdk1.8中HttpURLConnection的getOutpuStream()方法的源码 解决办法删掉getOutputStream()用url传参。 正确代码 public class GET200 {public static void main(String[] args) {try {String defURL https://httpbin.org/get;String body usernamexiaohupassword123456;URL url new URL(defURL?body);// 打开和URL之间的连接HttpURLConnection con (HttpURLConnection) url.openConnection();con.setRequestMethod(GET);//请求get方式// System.out.println(http请求方法:con.getRequestMethod());System.out.println(http状态码: con.getResponseCode());// 获取服务端响应通过输入流来读取URL的响应InputStream is con.getInputStream();BufferedReader reader new BufferedReader(new InputStreamReader(is, UTF-8));StringBuffer sbf new StringBuffer();String strRead null;while ((strRead reader.readLine()) ! null) {sbf.append(strRead);sbf.append(\r\n);}reader.close();// 关闭连接con.disconnect();// 打印读到的响应结果System.out.println(运行结束 sbf.toString());} catch (Exception e) {e.printStackTrace();}} }运行结果 http状态码:200 运行结束{args: {password: 123456, username: xiaohu}, headers: {Accept: text/html, image/gif, image/jpeg, *; q.2, */*; q.2, Host: httpbin.org, User-Agent: Java/1.8.0_221, X-Amzn-Trace-Id: Root1-668a1ba0-278338c97b93d6ca4276c0b0}, origin: 113.57.25.151, url: https://httpbin.org/get?usernamexiaohupassword123456 }使用GET方法访问POST接口服务端返回405 发生场景接口文档显示接口为GET接口实际上后端人员写的是POST接口文档没同步。 错误代码 public class GETtoPOST405 {public static void main(String[] args) {try {String defURL https://httpbin.org/post;String bodyusernamexiaohupassword123456;URL url new URL(defURL ? body);HttpURLConnection con (HttpURLConnection) url.openConnection(); // con.setUseCaches(false); // Post请求不能使用缓存con.setRequestMethod(GET);//请求get方式con.setDoInput(true);// 设置是否从HttpURLConnection输入默认值为 truecon.setDoOutput(false);// 设置是否使用HttpURLConnection进行输出默认值为 falseint code con.getResponseCode();System.out.println(http状态码: code);if (code HttpURLConnection.HTTP_OK) {System.out.println(测试成功);} else {System.out.println(测试失败 code);}// 获取服务端响应通过输入流来读取URL的响应InputStream is con.getInputStream();BufferedReader reader new BufferedReader(new InputStreamReader(is, UTF-8));StringBuffer sbf new StringBuffer();String strRead null;while ((strRead reader.readLine()) ! null) {sbf.append(strRead);sbf.append(\r\n);}reader.close();// 关闭连接con.disconnect();// 打印读到的响应结果System.out.println(运行结束 sbf.toString());} catch (Exception e) {e.printStackTrace();}} } 报错log: http状态码:405 测试失败405Caused by: java.io.IOException: Server returned HTTP response code: 405 for URL: https://httpbin.org/post?usernamexiaohupassword123456405原因不知道后端接口的定义或者没有沟通彻底或者后端开发人员失误本应该是GET定义成了POST。应该使用POST方法。 解决方法使用POST请求。 正确代码 public class POSTtoPOST200 {public static void main(String[] args) {try {String defURL https://httpbin.org/post;URL url new URL(defURL);HttpURLConnection con (HttpURLConnection) url.openConnection(); // con.setUseCaches(false); // Post请求不能使用缓存con.setRequestMethod(POST);//请求POST方式con.setDoOutput(true);// 设置是否使用HttpURLConnection进行输出默认值为 falseOutputStreamWriter writer new OutputStreamWriter(con.getOutputStream(), UTF-8);String body usernamexiaohupassword123456;writer.write(body);writer.flush();int code con.getResponseCode();System.out.println(http状态码: code);if (code HttpURLConnection.HTTP_OK) {System.out.println(测试成功);} else {System.out.println(测试失败 code);}// 获取服务端响应通过输入流来读取URL的响应InputStream is con.getInputStream();BufferedReader reader new BufferedReader(new InputStreamReader(is, UTF-8));StringBuffer sbf new StringBuffer();String strRead null;while ((strRead reader.readLine()) ! null) {sbf.append(strRead);sbf.append(\r\n);}reader.close();// 关闭连接con.disconnect();// 打印读到的响应结果System.out.println(运行结束 sbf.toString());} catch (Exception e) {e.printStackTrace();}} }运行结果 http状态码:200 测试成功 运行结束{args: {}, data: , files: {}, form: {password: 123456, username: xiaohu}, headers: {Accept: text/html, image/gif, image/jpeg, *; q.2, */*; q.2, Content-Length: 31, Content-Type: application/x-www-form-urlencoded, Host: httpbin.org, User-Agent: Java/1.8.0_221, X-Amzn-Trace-Id: Root1-668a2091-2a64856935929fab74082ce4}, json: null, origin: 113.57.25.151, url: https://httpbin.org/post } 使用POST方法访问GET接口服务端返回405 发生场景代码失误本该写GET写成了POST。 错误代码 public class POSTtoGET405 {public static void main(String[] args) {try {String defURL https://httpbin.org/get;URL url new URL(defURL);// 打开和URL之间的连接HttpURLConnection con (HttpURLConnection) url.openConnection();con.setRequestMethod(POST);//请求post方式 // con.setUseCaches(false); // Post请求不能使用缓存con.setDoInput(true);// 设置是否从HttpURLConnection输入默认值为 truecon.setDoOutput(true);// 设置是否使用HttpURLConnection进行输出默认值为 falseOutputStreamWriter writer new OutputStreamWriter(con.getOutputStream(), UTF-8);String body usernamexiaohupassword123456;writer.write(body);writer.flush();writer.close();int code con.getResponseCode();System.out.println(http状态码: code);if (code HttpURLConnection.HTTP_OK) {System.out.println(测试成功);} else {System.out.println(测试失败 code);}// 获取服务端响应通过输入流来读取URL的响应InputStream is con.getInputStream();BufferedReader reader new BufferedReader(new InputStreamReader(is, UTF-8));StringBuffer sbf new StringBuffer();String strRead null;while ((strRead reader.readLine()) ! null) {sbf.append(strRead);sbf.append(\r\n);}reader.close();// 关闭连接con.disconnect();// 打印读到的响应结果System.out.println(运行结束 sbf.toString());} catch (Exception e) {e.printStackTrace();}} }405原因 接口只接受GET方法请求是POST方法。 错误场景后端开发定义失误本该是POST接口写成了GET。接口没有测试。 解决办法用GET访问。正确代码和GET访问GET一样。
http://www.w-s-a.com/news/421235/

相关文章:

  • 做网站维护需要懂什么网站后台后缀名
  • 网站建设的认可桂平市住房和城乡建设局网站
  • 网站设计师岗位职责域名关键词查询
  • 百度怎样建设网站盐城公司网站建设
  • 站长工具国产2023网站制作 商务
  • 网络新闻专题做的最好的网站杭州网站设计建设公司
  • 电商网站界面设计流程ps培训班一般学费多少钱
  • 西安网站运营上海闵行区网站制作公司
  • 宁波网站推广代运营长链接转化成短链接工具
  • 小企业如何建网站怎么自己制作app
  • 苏州品牌网站制作公司宁波建设工程有限公司
  • 合肥网站建设zgkr互联网创业好项目
  • 哪里学网站建设与管理云落wordpress
  • 网站建设意见做网站涉及到哪些
  • 网站导航栏原型图怎么做怎么样创建一个网站
  • 遨游建站金融网站建站
  • cms企业网站模板上海网站开发平台
  • 贵阳网站建设搜q479185700网站团队建设
  • 电商网站建设 教学总结蚌埠市住房建设部网站
  • 深圳罗湖企业网站发稿类别是什么
  • 做网站基本语言企业应用软件开发
  • 网站建设与运营 市场分析影视小程序搭建
  • vs 团队网站开发中铁建设门户网登录咋进不去了
  • 快速网站建设公司哪家好优秀的网站建设
  • 网站开发的自适应wordpress搜索词结果按文章标题
  • 微网站是用什么开发的wordpress中英文主题
  • 纯静态网站怎么做淄博seo开发
  • 江西新农村建设权威网站盐步网站制作
  • 网站ui设计例子怎么做打鱼网站
  • 在1688做公司网站wordpress category