|
各位大侠,上午好,web service 无法获取数据,麻烦帮忙看看,谢谢。
public int PostRequest(string Url, string user, string pwd, string paramData, Encoding MsgEncode)
{
if (string.IsNullOrEmpty(Url))
{
throw new ArgumentNullException("Url");
}
if (MsgEncode == null)
{
throw new ArgumentNullException("MsgEncoding");
}
string username = user;
string password = pwd;
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(Url), "Digest", new NetworkCredential(username, password));
ServicePointManager.ServerCertificateValidationCallback
+= RemoteCertificateValidate; //自動回覆證書
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Url);
Request.Credentials = mycache;
Request.Headers.Add("Authorization", "Digest" + Convert.ToBase64String(MsgEncode.GetBytes(usernamePassword)));
Request.Method = "POST";
//Request.Timeout = 1000;
Request.ContentType = "application/x-www-form-urlencoded";
string temp_paramData = "json = " + System.Web.HttpUtility.UrlEncode(paramData);
byte[] byteArray = MsgEncode.GetBytes(temp_paramData);
Request.ContentLength = byteArray.Length;
Request.UseDefaultCredentials = false;
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(Url));
HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse(); ---出现数据流错误
Stream stream = webreponse.GetResponseStream();
byte[] rsByte = new Byte[webreponse.ContentLength];
string aa = System.Text.Encoding.UTF8.GetString(rsByte, 0, rsByte.Length).ToString();
Response.Write(aa);
|
|