| 1 |
using System; |
|---|
| 2 |
using System.IO; |
|---|
| 3 |
using System.Net; |
|---|
| 4 |
using System.Text; |
|---|
| 5 |
|
|---|
| 6 |
namespace Xameleon.Function { |
|---|
| 7 |
|
|---|
| 8 |
public class HttpWebRequestStream { |
|---|
| 9 |
|
|---|
| 10 |
public HttpWebRequestStream () { } |
|---|
| 11 |
|
|---|
| 12 |
public static string GetResponse ( String uri ) { |
|---|
| 13 |
return new WebClient().DownloadString(uri); |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
public static string GetResponse ( String uri, String formValues ) { |
|---|
| 17 |
WebRequest myHttpWebRequest = WebRequest.Create(uri); |
|---|
| 18 |
|
|---|
| 19 |
myHttpWebRequest.Method = "POST"; |
|---|
| 20 |
string postData = formValues; |
|---|
| 21 |
ASCIIEncoding encoding = new ASCIIEncoding(); |
|---|
| 22 |
byte[] byte1 = encoding.GetBytes(postData); |
|---|
| 23 |
|
|---|
| 24 |
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; |
|---|
| 25 |
|
|---|
| 26 |
myHttpWebRequest.ContentLength = byte1.Length; |
|---|
| 27 |
|
|---|
| 28 |
using (Stream newStream = myHttpWebRequest.GetRequestStream()) { |
|---|
| 29 |
newStream.Write(byte1, 0, byte1.Length); |
|---|
| 30 |
} |
|---|
| 31 |
return GetResponseString(myHttpWebRequest.GetResponse().GetResponseStream()); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
public static string GetResponseString ( Stream stream ) { |
|---|
| 35 |
using (StreamReader reader = new StreamReader(stream)) { |
|---|
| 36 |
return reader.ReadToEnd(); |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
//public static string GetResponse (String uri, bool returnUri) { |
|---|
| 41 |
// WebRequest myHttpWebRequest = WebRequest.Create(uri); |
|---|
| 42 |
// myHttpWebRequest.Method = "GET"; |
|---|
| 43 |
// if (!returnUri) { |
|---|
| 44 |
// return GetResponseString(myHttpWebRequest.GetResponse().GetResponseStream()); |
|---|
| 45 |
// } else { |
|---|
| 46 |
// return myHttpWebRequest.GetResponse().ResponseUri.ToString(); |
|---|
| 47 |
// } |
|---|
| 48 |
//} |
|---|
| 49 |
} |
|---|
| 50 |
} |
|---|