OpenURL ( webpost , get)
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.IO;
using System.Text;
public class Module1
{
private static CookieContainer cookie = new CookieContainer();
public string OpenURL(string URL, string Method = "GET", string PostData = null)
{
string functionReturnValue = null;
HttpWebRequest request = null;
request = (HttpWebRequest)WebRequest.Create(URL);
var _with1 = request;
_with1.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
_with1.ContentType = "application/x-www-form-urlencoded";
_with1.Accept = "*/*";
_with1.KeepAlive = true;
_with1.ReadWriteTimeout = -1;
_with1.Timeout = -1;
_with1.Method = Method;
// get,post등을 설정
_with1.CookieContainer = cookie;
if (Method == "POST")
{
TextWriter w = new StreamWriter(_with1.GetRequestStream());
w.Write(PostData);
w.Close();
w = null;
}
HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
var _with2 = Response;
if (_with2.StatusCode == HttpStatusCode.OK)
{
Stream receivestream = _with2.GetResponseStream();
StreamReader readstream = null;
readstream = new StreamReader(receivestream, System.Text.Encoding.UTF8);
functionReturnValue = readstream.ReadToEnd();
readstream.Close();
_with2.Close();
}
return functionReturnValue;
}
}