프로그래밍언어/VB.NET

VB6 -> C# 포팅, 네이버 로그인, 네이버 쪽지 전송, 네이버 메일 전송

부산딸랑이 2013. 1. 24. 06:20
네이버 로그인:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public static bool NaverLogin(string ID, string PW, CookieContainer cookie)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://nid.naver.com/nidlogin.login");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Referer = "https://nid.naver.com/nidlogin.login";
    request.CookieContainer = cookie;
    StreamWriter swriter = new StreamWriter(request.GetRequestStream());
    swriter.Write("enctp=2&svctype=0&id=" + ID + "&pw=" + PW);
    swriter.Close();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.StatusCode == HttpStatusCode.OK)
    {
        Stream resStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(resStream, Encoding.Default);
        string result = readStream.ReadToEnd();
        resStream.Close();
        readStream.Close();
        if (result.IndexOf("http://static.nid.naver.com/sso/cross-domain.nhn") >= 0)
            return true;
    }
    return false;
}
네이버 쪽지 전송:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public static bool NaverMessage(string to, string body, CookieContainer cookie)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://m.note.naver.com/mobile/mobileCaptchaViewCheck.nhn?");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.CookieContainer = cookie;
    StreamWriter swriter = new StreamWriter(request.GetRequestStream());
    swriter.Write("fromUrl=%2Fmobile%2FmobileSendNoteForm.nhn%3FselfSend%3D0&returnUrl=http%3A%2F%2Fm.note.naver.com%2Fmobile%2FmobileReceiveList.nhn&svcType=0&svcId=&svcName=&svcTitle=&svcLink=¬e=" + System.Web.HttpUtility.UrlEncode(body, Encoding.Default) + "&targetId=" + to + "&isBackup=true&isReplyNote=false");
    swriter.Close();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.StatusCode == HttpStatusCode.OK)
    {
        Stream resStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(resStream, Encoding.UTF8);
        string result = readStream.ReadToEnd();
        resStream.Close();
        readStream.Close();
        if (result.IndexOf("성공") >= 0)
            return true;
    }
    return false;
}

네이버 메일 전송:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public static bool NaverMail(string id, string senderName, string to, string subject, string body, CookieContainer cookie)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://mail.naver.com/json/write/send/");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Referer = "http://mail.naver.com/";
    request.CookieContainer = cookie;
    StreamWriter swriter = new StreamWriter(request.GetRequestStream());
    swriter.Write("senderName=" + senderName + "&to=" + to + "&cc=&bcc=&subject=" + subject + "&body=" + body + "&contentType=html&charset=AUTO&sendSeparately=false&saveSentBox=true&type=new&fromMe=0&attachID=tseCWrwm_LYmKoumKSevFou97qUm7riGWzwCMBKTM40nWzJCbqMZKAEwKou.&reserveDate=&reserveGMT=&reserveTime=&calendarVal=&autoSaveMailSN=&addReceiverAddress=false&attachCount=0&attachSize=0&bigfile=&sessionID=&seqNums=&priority=0&ndriveFileInfos=&lists=&serviceID=&u=" + id);
    swriter.Close();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    if (response.StatusCode == HttpStatusCode.OK)
    {
        Stream resStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(resStream, Encoding.UTF8);
        string result = readStream.ReadToEnd();
        resStream.Close();
        readStream.Close();
        if (result.IndexOf("성공") >= 0)
            return true;
    }
    return false;
}



출처 : http://exynoa.tistory.com/193

 

httprequest

'프로그래밍언어 > VB.NET' 카테고리의 다른 글

2013년 1월 24일 오전 06:21  (0) 2013.01.24
MNET정규식연습  (0) 2013.01.24
타이머소스  (0) 2013.01.24
VB.NET에서 엑셀 Application객체사용법   (0) 2013.01.24
2013년 1월 19일 오전 01:48  (0) 2013.01.19