您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页java.net.URISyntaxException: Illegal character in scheme name at index 0

java.net.URISyntaxException: Illegal character in scheme name at index 0

来源:爱够旅游网

在做微信公众号服务,网页获取用户授权的时候报错,如图:

		String url=" https://api.weixin.qq.com/sns/oauth2/access_token" +
					"?" +Wechat_Appid+Wechat_Secret+
					"&code=" +code+
					"&grant_type=authorization_code";
		url= URLEncoder.encode(url,"UTF-8");
		JSONObject jsonObject = HttpUntil.sendPostNoreturn(url);

还有其他方式修改:

import java.net.*;

public class Test {
  public static void main(String[] args) {
    String myURL = "http://finance.yahoo.com/q/h?s=^IXIC";
    try {
      URL url = new URL(myURL);
      String nullFragment = null;
      URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), nullFragment);
      System.out.println("URI " + uri.toString() + " is OK");
    } catch (MalformedURLException e) {
      System.out.println("URL " + myURL + " is a malformed URL");
    } catch (URISyntaxException e) {
      System.out.println("URI " + myURL + " is a malformed URL");
    }
  }
}
import java.net.*;
import java.io.*;

public class EncodeParameter { 

    public static void main( String [] args ) throws URISyntaxException ,
                                         UnsupportedEncodingException   { 

        String myQuery = "^IXIC";

        URI uri = new URI( String.format( 
                           "http://finance.yahoo.com/q/h?s=%s", 
                           URLEncoder.encode( myQuery , "UTF8" ) ) );

        System.out.println( uri );

    }
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务