Android Volley MalformedURLException错误的URL [英] Android Volley MalformedURLException Bad URL
问题描述
使用Volley
发出第二个网络请求后,总是出现此错误.我输入的网址似乎并不重要. Volley
始终声称其格式错误.
After making a second network request using Volley
, I always get this error. It doesn't seem to matter what the url I put in is. Volley
always claims it is malformed.
08-04 20:16:26.885 14453-14470/com.thredup.android E/Volley﹕ [994] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:127)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:110)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:101)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
进一步调查,我在HurlStack中放置了一些日志.在
Investigating further, I put a couple logs in HurlStack. In
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders),
失败的请求是REQUEST [ ] 0x0 LOW 26.
"
因此,HurlStack的第101行:URL parsedUrl = new URL(url);
Thus, line 101 of HurlStack : URL parsedUrl = new URL(url);
网址为空(request.getUrl()
为空)失败.
fails with an empty url (request.getUrl()
is empty).
我正在使用OkHttpStack
(扩展HurlStack).
关于可能导致这种情况的任何想法?
I am using OkHttpStack
(extending HurlStack).
Any ideas on what could be causing this?
推荐答案
实际上,问题出在您的网址,而不是凌空.您的网址不是URI.其中没有协议组件.它需要http://
或您打算使用的任何其他协议.如果您的网址中包含http,请确保网址的格式正确无误.
actually the problem is with your url not with the volley. Your Url is not a URI. There is no protocol component in it. It needs http://
or whatever other protocol you intend. If you have the http in your url make sure where it is correctly formed or not.
例如,您的网址格式应为
For example your url formation should be like this
public String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
别忘了阅读 URL规范,并确保您提供的URL有效.
Don’t forget to read the URL Specification and make sure the URL you are providing is valid.
这篇关于Android Volley MalformedURLException错误的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!