| |

VerySource

 Forgot password?
 Register
Search
View: 788|Reply: 5

HttpWebRequest problem, please help from experts!

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-25 09:00:02
| Show all posts |Read mode
I want to rewrite an XMLHTTP written by asp into HttpWebRequest with asp.net:
strURL="http://www.website-export.com/cgi-bin/cnps.cgi?"&cnpsStr
  Set WinHttpReq = server.CreateObject("Microsoft.XMLHTTP")
  
  WinHttpReq.Open "GET", strURL, false
  WinHttpReq.SetRequestHeader "REMOTE_HOST", Request.ServerVariables("SERVER_NAME")
  WinHttpReq.SetRequestHeader "URL", Request.ServerVariables("URL")

  WinHttpReq.Send
  
  strResult = WinHttpReq.ResponseText
  PostCnpsRequest = strResult
To:
Encoding encoding = Encoding.GetEncoding("GB2312");
string postData="user_id="+"1485";
postData += ("&origin_zip="+"100071");
postData+=("&desti_zip="+desti_zip);
postData+=("&shipping_weight="+shipping_weight);
postData+=("&shipping_method="+"parcel_post");
string strUrl = "http://www.website-export.com/cgi-bin/cnps.cgi";

byte[] data = encoding.GetBytes(postData);

// Prepare the request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.ContentType="www.car8848.cn/ProductPSFS.aspx";

myRequest.ContentLength = data.Length;

Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();

WebResponse response = myRequest.GetResponse();

Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
Response.Write (sr.ReadToEnd());
resStream.Close();
sr.Close();
among them
WinHttpReq.SetRequestHeader "REMOTE_HOST", Request.ServerVariables("SERVER_NAME")
  WinHttpReq.SetRequestHeader "URL", Request.ServerVariables("URL")

How can this be expressed in asp.net?
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-11-25 09:15:02
| Show all posts
myRequest.Headers.Add( "REMOTE_HOST",
Request.ServerVariables("SERVER_NAME"));

myRequest.Headers.Add( "URL", Request.ServerVariables("URL"));

___________
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-25 10:00:02
| Show all posts
System.Web.HttpRequest.ServerVariables means "attribute, where it should be "method"
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-11-25 10:30:01
| Show all posts
System.Web.HttpRequest.ServerVariables[""]
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-11-25 10:45:01
| Show all posts
It's all here:


foreach(string key in Request.ServerVariables)
{
Response.Write(key +" = "+ Request.ServerVariables[key] +"<BR>");
}
Reply

Use magic Report

1

Threads

2

Posts

1.00

Credits

Newbie

Rank: 1

Credits
1.00

 China

Post time: 2020-12-1 09:40:12
| Show all posts
Support
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list