当前位置: 代码迷 >> 综合 >> 解决问题-2【java.io.IOException: Server returned HTTP response code: 500 for URL】
  详细解决方案

解决问题-2【java.io.IOException: Server returned HTTP response code: 500 for URL】

热度:90   发布时间:2023-12-12 04:38:47.0

报错信息:


java.io.IOException: Server returned HTTP response code: 500 for URL: `你的url地址`at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)at common.ApiClient.sendRequest(ApiClient.java:54)at common.ApiClient.sendPostRequest(ApiClient.java:29)at Product_Api_Function.Product_Sku_Map_Search.Product_sku_map_search(Product_Sku_Map_Search.java:58)at testcase.Test_ProductSkuMapSearch_case01.ProductSkuMapSearch_01(Test_ProductSkuMapSearch_case01.java:23)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)at org.testng.TestRunner.privateRun(TestRunner.java:648)at org.testng.TestRunner.run(TestRunner.java:505)at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)at org.testng.SuiteRunner.run(SuiteRunner.java:364)at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)at org.testng.TestNG.runSuites(TestNG.java:1049)at org.testng.TestNG.run(TestNG.java:1017)at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

解决思路:
1、用相同的参数在postman请求,可以请求通过,但是在代码里面请求就不行;虽然报500的错误,但是可以肯定不是后台的问题了

2、通过百度查到;可能是因为参数有空格的关系,所以将代码请求的地方加了utf-8的编码方式
修改:(然后运行就能解决这个问题)
params = java.net.URLEncoder.encode(params, "UTF-8");在这里插入图片描述

特别感谢:https://blog.csdn.net/qq_43424359/article/details/90549404

  相关解决方案