1

我正在尝试制作一个应用程序,以便每次我推送它时,它都会登录到网页并在那里解析一些信息。问题是我无法使登录正常工作。这是到目前为止的代码:

       DefaultHttpClient httpClient = new DefaultHttpClient();
       HttpPost httpPost = new HttpPost("http://staff.ezshift.co.il/appfilesv3/loginHE-il.aspx?c=Intel");
       HttpGet getContacts = new HttpGet("http://staff.ezshift.co.il/appfilesv3/loginHE-il.aspx?c=Intel");          
       HttpResponse response = null;
       httpPost.setHeader("Host","staff.ezshift.co.il");
       httpPost.setHeader("Connection","keep-alive");
       httpPost.setHeader("Content-Length","391");
       httpPost.setHeader("Cache-Control","max-age=0");
       httpPost.setHeader("Origin","http://staff.ezshift.co.il");
       httpPost.setHeader("Keep-Alive","115");
       httpPost.setHeader("Proxy-Connection","keep-alive");
       httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1");
       httpPost.setHeader("Content-Type","application/x-www-form-urlencoded"); //maybe the cause or 500 when i do get first
       httpPost.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, value");
       httpPost.setHeader("Referer","http://staff.ezshift.co.il/appfilesV3/loginHE-il.aspx");
       httpPost.setHeader("Accept-Encoding","gzip,deflate,sdch");
       httpPost.setHeader("Accept-Language","he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4");
       httpPost.setHeader("Accept-Charset","windows-1255,utf-8;q=0.7,*;q=0.3");
       httpPost.setHeader("Cookie","__utma=215140181.649912737.1328214019.1334209515.1334386068.42; __utmz=215140181.1329665293.8.2.utmcsr=cmcc.intel.com|utmccn=(referral)|utmcmd=referral|utmcct=/; ASP.NET_SessionId=vfeqxcds4pf5wkaqrdggk2rc; ASPSESSIONIDCCCCBBBQ=BBHDANFDIKPKIMEEIEIKLLOL; __utma=124032085.1089828467.1345030012.1345764967.1345783785.15;  __utmb=124032085.1.10.1345783785; __utmc=124032085; __utmz=124032085.1345030012.1.1.utmcsr= (direct)|utmccn=(direct)|utmcmd=(none)");
       List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
       nameValuePairs.add(new BasicNameValuePair("__VIEWSTATE", "/FwEPDwUJODI5ODQ3NDUwZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUPY2hrU2F2ZVBhc3N3b3JkBQxJbWFnZUJ1dHRvbjFMNmoQnT0M/y17bSJbfWm6bATcQjZ2rP5yHUSXIqIs6A=="));
       nameValuePairs.add(new BasicNameValuePair("__EVENTVALIDATION", "/FwEWBgLb/I3LDAKM+5bqDwK1qbSRCwLer5GzDwK2q+7XBwLSwpnTCLBEbw+HDaExaRbSqYX7LbeoaRVs7AKaXw5Rbn6YQ1Ti"));
       nameValuePairs.add(new BasicNameValuePair("txtId", Myid));
       nameValuePairs.add(new BasicNameValuePair("txtPassword", MyPassword));
       nameValuePairs.add(new BasicNameValuePair("ImageButton1.x", "0"));
       nameValuePairs.add(new BasicNameValuePair("ImageButton1.y", "0"));
       String siteCode = null;
       try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

        try {
        response = httpClient.execute(httpPost);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        textPushed.setText(e.toString());

    }
       int rep = response.getStatusLine().getStatusCode();
       if (response.getStatusLine().getStatusCode() <= 302) {

           getContacts = new HttpGet("http://staff.ezshift.co.il/appfilesV3/Entrance.aspx");
           try {
            response = httpClient.execute(getContacts);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

问题是我一直在 response.getStatusLine().getStatusCode() = 500 关注我登录时它通过了哪些标题,这就是我所看到的:

Request URL:http://staff.ezshift.co.il/appfilesV3/loginHE-il.aspx?bLogo=True&bTopImage=False&c=intel
Request Method:POST
Status Code:302 Found
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:windows-1255,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:365
Content-Type:application/x-www-form-urlencoded
Cookie:__utma=215140181.649912737.1328214019.1334209515.1334386068.42;
__utmz=215140181.1329665293.8.2.utmcsr=cmcc.intel.com|utmccn=    (referral)|utmcmd=referral|utmcct=/; ASP.NET_SessionId=vfeqxcds4pf5wkaqrdggk2rc;     ASPSESSIONIDCCCCBBBQ=BBHDANFDIKPKIMEEIEIKLLOL;     __utma=124032085.1089828467.1345030012.1345824347.1345827099.19;     __utmb=124032085.2.10.1345827099; __utmc=124032085; __utmz=124032085.1345030012.1.1.utmcsr=    (direct)|utmccn=(direct)|utmcmd=(none)
Host:staff.ezshift.co.il
Origin:http://staff.ezshift.co.il
Referer:http://staff.ezshift.co.il/appfilesV3/loginHE-il.aspx?   bLogo=True&bTopImage=False&c=intel
 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko)     Chrome/21.0.1180.83 Safari/537.1
Query String Parametersview URL encoded
bLogo:True
bTopImage:False
c:intel
Form Dataview URL encoded
__VIEWSTATE:/wEPDwUJODI5ODQ3NDUwZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUPY2hrU2F2  ZVBhc3N3b3JkBQxJbWFnZUJ1dHRvbjFMNmoQnT0M/y17bSJbfWm6bATcQjZ2rP5yHUSXIqIs6A==
   __EVENTVALIDATION:/wEWBQLb/I3LDAKM+5bqDwK1qbSRCwK2q+7XBwLSwpnTCCXh+wP+hEsOO7tFqG7dYMq98gP9doLDEPj9RGtONL81
txtId:Myid
txtPassword:MyPassword
ImageButton1.x:49
ImageButton1.y:26
Response Headersview source
Cache-Control:private
Content-Length:142
Content-Type:text/html; charset=utf-8
Date:Fri, 24 Aug 2012 16:51:58 GMT
Location:/appfilesV3/Entrance.aspx
Set-Cookie:UserInfo=; expires=Thu, 23-Aug-2012 16:51:58 GMT; path=/
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

我错过了什么?我究竟做错了什么?

谢谢。

4

0 回答 0