ASP.NET网站上的Java中的HTTPS POST请求

时间:2013-03-13 11:16:21

标签: java url urlencode

我无法在asp.net网站上发布请求。 当我在php上尝试使用localhost时,它的工作正常,但是在网络asp.net网站上却无法正常工作。

请有人帮助我。

    package cc.cu.desertcreator;

    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLEncoder;
    import java.io.BufferedReader;

    public class Test {

    public static void main(String[] args) {
        try {
            // Construct data
            String data = URLEncoder.encode("__EVENTTARGET", "UTF-8") + "="
                    + URLEncoder.encode("", "UTF-8");
            data += "&" + URLEncoder.encode("__EVENTARGUMENT", "UTF-8") + "="
                    + URLEncoder.encode("", "UTF-8");

            data += "&" + URLEncoder.encode("__VIEWSTATE", "UTF-8") + "="
                    + URLEncoder.encode("/wEPDwUJMjQ4Njc3OTkzD2QWAmYPZBYCZg9kFgJmD2QWCGYPZBYGAgEPZBYCAgMPFgIeC18hSXRlbUNvdW50Av////8PZAIDDxYCHgdjb250ZW50BRIxMjAzMjAzOTYxLDM2MDYzNTJkAgQPFQENJ1VBLTcxODc2MC0xJ2QCBg8WAh4HVmlzaWJsZWhkAgcPDxYCHwJoZGQCCA9kFgICAQ9kFgICARBkZBYCAgEPZBYCAgkPZBYCZg9kFgICAQ9kFgICAQ9kFgICAw8PFgIeEkVuYWJsZUNsaWVudFNjcmlwdGhkZGRPA99uYkD6em3jusGYVPJ/ioe47g==", "UTF-8");
            data += "&" + URLEncoder.encode("userPrefs", "UTF-8") + "="
                    + URLEncoder.encode("", "UTF-8");
            data += "&" + URLEncoder.encode("M$ctl00$ctl00$MainContent$MainContent$MainContent$eh", "UTF-8") + "="
                    + URLEncoder.encode("value2", "UTF-8");
            data += "&" + URLEncoder.encode("M$ctl00$ctl00$MainContent$MainContent$MainContent$c7$tb_email", "UTF-8") + "="
                    + URLEncoder.encode("asikpstu@gmail.com", "UTF-8");
            // Send data
            URL url = new URL("https://www.prosper.com/account/common/login.aspx");
            URLConnection conn = url.openConnection();
            conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(
                    conn.getOutputStream());
            wr.write(data);
            wr.flush();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        } catch (Exception e) {
        }
    }
}

输出应该转到网页源,但它会返回:

--------------------Configuration: <Default>--------------------
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://m.prosper.com/account/common/login.aspx">here</a></h2>
</body></html>

0 个答案:

没有答案