0

我正在尝试在 C# 中进行 webrequest,这类似于 PHP 中的 CurL。但我不断收到身份验证问题。我想知道问题出在我的凭据还是我提出的网络请求中。以下是我要复制的 PHP CurL 请求的代码:

$search = $searchurl . "type=player&start=$start&num=$count" . $searchstring;
        //Set the cookie data
        $cookie_string = $this->EASW_KEY."; ".$this->EASF_SESS ."; ".$this->PHISHKEY;                                                                       
        //Setup cURL HTTP request
        $ch = curl_init($search);                                                                      
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                                                                                     
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_COOKIE, $cookie_string); 
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
            'Content-Type: application/json',                                                                                
            'x-http-method-override: GET',
            $this->XSID)                                                                       
        );

        //Contains the JSON file returned from EA
        $EAPSEARCH = curl_exec($ch);
        curl_close($ch);

到目前为止,这是我为使其在 C# 中工作所做的工作:

string data = this.easwKey + ";" + this.phishKey;
byte[] buffer = Encoding.ASCII.GetBytes(this.sid); //the data you want to send to the web service
                HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(urlPath);
                WebReq.Method = "POST";
                WebReq.ContentType = "application/json";
                WebReq.ContentLength = buffer.Length;
                WebReq.Headers["Cookie"] = data;
                WebReq.Headers["X-HTTP-Method-Override"] = "GET";

                Stream PostData = WebReq.GetRequestStream();
                PostData.Write(buffer, 0, buffer.Length);
                PostData.Close();
                HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
                Stream Answer = WebResp.GetResponseStream();
                StreamReader _Answer = new StreamReader(Answer);
                returnStr = _Answer.ReadToEnd();

returnStr总是返回,说未经授权..但code error of 401我可以使用相同的凭据登录系统..

4

0 回答 0