asp.net HttpWebRequest POST GET 数据

  1. protectedstringGETFileData(stringTheURL)
  2. {
  3. try
  4. {
  5. Uriuri=newUri(TheURL);
  6. System.Net.HttpWebRequestrequest=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
  7. request.Method="GET";
  8. request.ContentType="application/x-www-form-urlencoded";
  9. request.AllowAutoRedirect=false;
  10. request.Timeout=5000;
  11. System.Net.HttpWebResponseresponse=(System.Net.HttpWebResponse)request.GetResponse();
  12. StreamresponseStream=response.GetResponseStream();
  13. StreamReaderreadStream=newStreamReader(responseStream,System.Text.Encoding.UTF8);
  14. stringretext=readStream.ReadToEnd().ToString();
  15. readStream.Close();
  16. returnretext;
  17. }
  18. catch(Exceptionex)
  19. {
  20. returnex.ToString();
  21. }
  22. }
  23. protectedstringPostFileData(stringTheURL,byte[]data)
  24. {
  25. try
  26. {
  27. Uriuri=newUri(TheURL);
  28. System.Net.HttpWebRequestrequest=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
  29. request.Method="POST";
  30. request.ContentType="application/x-www-form-urlencoded";
  31. request.AllowAutoRedirect=false;
  32. request.Timeout=5000;
  33. request.ContentLength=data.Length;
  34. StreamnewStream=request.GetRequestStream();
  35. newStream.Write(data,0,data.Length);
  36. newStream.Close();
  37. System.Net.HttpWebResponseresponse=(System.Net.HttpWebResponse)request.GetResponse();
  38. StreamresponseStream=response.GetResponseStream();
  39. StreamReaderreadStream=newStreamReader(responseStream,System.Text.Encoding.UTF8);
  40. stringretext=readStream.ReadToEnd().ToString();
  41. readStream.Close();
  42. returnretext;
  43. }
  44. catch(Exceptionex)
  45. {
  46. returnex.ToString();
  47. }
  48. }

你可能感兴趣的:(.net,asp.net,asp)