gpt4 book ai didi

java - https 帖子 : MalformedURLException on App Engine

转载 作者:行者123 更新时间:2023-11-30 04:16:55 24 4
gpt4 key购买 nike

当我通过 GAE 身份验证向 url 发送 POST 请求时,我在 urlConn.getResponseCode() 函数上收到 MalformedURLException。

此问题仅在部署服务器上出现,当我在本地服务器上运行代码时不会出现。

Invalid URL specified: https://user:passtoken@twilix.exotel.in/v1/Accounts/user/Sms/send
java.net.MalformedURLException: Invalid URL specified: https://user:passtoken@twilix.exotel.in/v1/Accounts/user/Sms/send

at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:120)
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:43)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)

我的代码:

String urlString = 
"https://user:passtoken@twilix.exotel.in/v1/Accounts/user/Sms/send";
URL url = new URL(urlString.toString());
String userpass = "user:passtoken";
String basicAuth = "Basic " +
javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());

urlConn = (HttpURLConnection) url.openConnection();
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty ("Authorization", basicAuth);
urlConn.connect();
responseCode = urlConn.getResponseCode(); //Throws Exception

当我尝试将网址设置为 https://httpbin.org/post 时,一切正常

这是 GAE 的错误还是我的代码有问题?

最佳答案

看起来问题出在 & 符号上。由于您已经将凭据放入 HTTP 请求中,因此 URL 中也不需要它们。尝试将第一行更改为此。

String urlString = "https://twilix.exotel.in/v1/Accounts/user/Sms/send";

关于java - https 帖子 : MalformedURLException on App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18150269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com