用java准备请求一个url连接,url带查询参数。实现函数如下:public static void open_url()
    {
        try {
            String up_url = "http://192.168.1.60/upload/Default.aspx?id=1234567890";
            java.net.URL url = new java.net.URL(up_url);
            java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
        }
        catch (java.net.MalformedURLException e) {
            e.printStackTrace();
        }
        catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
服务端用.net 实现,现在问题是服务端取不到id和提交的参数。
想问的问题是,java这样增加参数是否正确,还是需要其他方法。

解决方案 »

  1.   


    InputStream inputStream = null;
    BufferedReader in = null;
    String path = null;
    try {
    path = ROOT_PATH
    + URLEncoder.encode(MESSAGE + smsContent + PHONE
    + phoneNumber + key, "utf-8");
    URL url;
    url = new URL(path);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(15000);
    conn.setReadTimeout(15000);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-type", "text/html");
    conn.setRequestProperty("Accept-Charset", "utf-8");
    conn.setRequestProperty("contentType", "utf-8");
    conn.setDoInput(true);
    inputStream = conn.getInputStream();
    String line;
    in = new BufferedReader(new InputStreamReader(inputStream), 1024);
    while ((line = in.readLine()) != null) {
    if (line.length() > 0) {
    Gson gson = new Gson();
    Type type = new TypeToken<SMSResult>() {
    }.getType();
    smsResult = gson.fromJson(line, type);
    }
    }
    } catch (Exception e) {
    throw e;
    } finally {
    try {
    if (null != in) {
    in.close();
    }
    if (null != inputStream) {
    inputStream.close();
    }
    } catch (Exception e) {
    throw e;
    }
    }楼主可以参考下  需要用POST
      

  2.   

    httpclient 例子很多哦  到网上看看
      

  3.   

    这样增加参数是可以的,不过有两个问题:
    1、漏了开启动作;
    2、.Net端,用的是POST方式接收参数还是GET方式?String urlString = "http://192.168.1.60/upload/Default.aspx?id=1234567890";  
    URL url = new URL(urlString);  
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection()  
    httpConn.setRequestMethod("GET");  // 访问方式
    httpConn.connect(); // 关键是这个动作别漏了