NAVER

질문 무엇이 잘못된것인지 원인을 모르겠어요
비공개 조회수 623 작성일2017.02.04
안녕하세요 첨부파일 올렸습니다
정부공공기관 워크넷 www.work.go.kr 계정 가지고 계신분만 확인 가능하실 것 같아요

이상하게 winhttp 에서만 문제가 발생합니다
inet 이나 httpwebrequest 에서는 정상인데요

도대체 런타임 오류가 발생하는 이유가 뭘까요?
inet 이나 httpwebrequest 사용하면 되지만 정말 원인을 모르겠어서 질문 남깁니다
※ 참고로 Cookie 값이나 모든 헤더 전부다 넣어줘도 마찬가지입니다


해결책을 알려주시면 채택 해드리겠습니다


 

프로필 사진

답변자님,

정보를 공유해 주세요.

1 개 답변
1번째 답변
안녕하세요~!   ^.^;;



아이디와 비번을 제공하면 모를까...


암튼 사용은 아래와 같은 형태로 하시면 됩니다.


그래야 winhttp에서 오류가 나더라도 쿠키값을 가지고 사용할 수있어요




Dim IE As Object
Dim Cookies As Variant
Dim Cookie As String
 
Sub worklogin()
    Dim strWorkID As String, strWorkPW As String
    Dim PostData As String, T As String
    strWorkID = "아이디"
    strWorkPW = "비밀번호"
    PostData = ""
    PostData = PostData & "redirectUrl=%2FseekWantedMain.do&"
    PostData = PostData & "lgovCustId=&"
    PostData = PostData & "ifOrgCd=&"
    PostData = PostData & "redirectEncodeYn=&"
    PostData = PostData & "custClcd=P&"
    PostData = PostData & "custId=" & strWorkID & "&"
    PostData = PostData & "pwd=" & strWorkPW & "&"
    PostData = PostData & "x=70&"
    PostData = PostData & "y=14"
    Set IE = CreateObject("WinHttp.WinHttpRequest.5.1")
    With IE
        .Open "POST""https://www.work.go.kr/member/login.do"
        .SetRequestHeader "Host""www.work.go.kr"
        .SetRequestHeader "User-Agent""Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
        .SetRequestHeader "Accept""text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        .SetRequestHeader "Accept-Language""ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3"
        .SetRequestHeader "DNT""1"
        .SetRequestHeader "Referer""http://www.work.go.kr/member/bodyLogin.do?redirectUrl=/seekWantedMain.do"
        If Len(Cookie) Then .SetRequestHeader "Cookie", Cookie
        .SetRequestHeader "Connection""keep-alive"
        .SetRequestHeader "Content-Type""application/x-www-form-urlencoded"
        .SetRequestHeader "Content-Length", Len(PostData)
        .Send PostData
        .WaitForResponse: DoEvents
        Cookie = Join(SetCookie(.GetAllResponseHeaders), "; ")
        T = .ResponseText
    End With
    If InStr(Cookie, "로그인 세션값"Then
        '// 로그인 성공
    Else
        '// 로그인 실패
    End If
    
    '// 또는
    
    If InStr(T, "로그아웃"Then
        '// 로그인 성공
    Else
        '// 로그인 실패
    End If
End Sub
 
 
Public Function SetCookie(Cookie As StringAs Variant
    Dim V As Variant, i As Integer, n As Integer, r As Integer
    V = Split(Cookie, "Set-Cookie: ")
 
    For i = To UBound(V)
        V(i) = Split(V(i), ";")(0)
    Next
    
    If TypeName(Cookies) = "Empty" Then
        r = -1
        ReDim Cookies(To 0)
        Cookies(0= "="
    Else
        r = UBound(Cookies)
    End If
    
    For i = To UBound(V)
        For n = To UBound(Cookies)
            If Split(V(i), "=")(0= Split(Cookies(n), "=")(0Then
                Cookies(n) = V(i)
                Exit For
            End If
        Next
        If UBound(Cookies) < n Then
            r = r + 1
            ReDim Preserve Cookies(To r)
            Cookies(r) = V(i)
        End If
    Next
    SetCookie = Cookies
End Function





2017.02.05.

  • 채택

    질문자가 채택한 답변입니다.

도움이 되었다면 UP 눌러주세요!
UP이 많은 답변일수록 사용자들에게 더 많이 노출됩니다.