java on .net_java.net.MalformedURLException: no protocol on URL

So I was attempting to use this String in a URL :-

http://site-test.collercapital.com/Meetings/IC/DownloadDocument?meetingId=c21c905c-8359-4bd6-b864-844709e05754&itemId=a4b724d1-282e-4b36-9d16-d619a807ba67&file=\\s604132shvw140\Test-Documents\c21c905c-8359-4bd6-b864-844709e05754_attachments\7e89c3cb-ce53-4a04-a9ee-1a584e157987\myDoc.pdf

In this code: -

String fileToDownloadLocation = //The above string

URL fileToDownload = new URL(fileToDownloadLocation);

HttpGet httpget = new HttpGet(fileToDownload.toURI());

But at this point I get the error: -

java.net.URISyntaxException: Illegal character in query at index 169:Blahblahblah

I realised with a bit of googling this was due to the characters in the URL (guessing the &), so I then added in some code so it now looks like so: -

String fileToDownloadLocation = //The above string

fileToDownloadLocation = URLEncoder.encode(fileToDownloadLocation, "UTF-8");

URL fileToDownload = new URL(fileToDownloadLocation);

HttpGet httpget = new HttpGet(fileToDownload.toURI());

However, when I try and run this I get an error when I try and create the URL, the error then reads: -

java.net.MalformedURLException: no protocol: http%3A%2F%2Fsite-test.collercapital.com%2FMeetings%2FIC%2FDownloadDocument%3FmeetingId%3Dc21c905c-8359-4bd6-b864-844709e05754%26itemId%3Da4b724d1-282e-4b36-9d16-d619a807ba67%26file%3D%5C%5Cs604132shvw140%5CTest-Documents%5Cc21c905c-8359-4bd6-b864-844709e05754_attachments%5C7e89c3cb-ce53-4a04-a9ee-1a584e157987%myDoc.pdf

It looks like I can't do the encoding until after I've created the URL else it replaces slashes and things which it shouldn't, but I can't see how I can create the URL with the string and then format it so its suitable for use. I'm not particularly familiar with all this and was hoping someone might be able to point out to me what I'm missing to get string A into a suitably formatted URL to then use with the correct characters replaced?

Any suggestions greatly appreciated!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值