Inet으로 정확히 무얼 하시는 건지는 잘 모르겠지만요..
vb.net에는 Inet을 대체할 클래스가 많습니다
대충 나열해보면
Webrequest, Webresponse,
webclient
그리고 inet과 비슷한 성질을 갖고 있는 윈도우의 winhttp.dll이 있습니다.
inet을 사용하지 못한다면 이 클래스나 dll로 바꾸시는 것이 어떠신지요?
여기 예시가 있습니다.
웹페이지 다운로드[GET]
[모두 a 변수에 웹페이지 소스가 저장됩니다.]
1) inet(vb6):
dim a as string
a = inet1.openurl("http://www.naver.com") 'openurl에 버그 존재
2) webrequest,webresponse(vb.net)
'imports system.net
'imports system.io
dim req as webrequest = webrequest.create("http://www.naver.com")
dim res as webresponse = req.getresponse()
Dim s As New StreamReader(res.GetResponseStream)
Dim a As String = s.ReadToEnd
s.close()
req.close()
3) webclient(vb.net)
'imports system.net
dim web as new webclient
dim a as string = webclient.downloadstring("http://www.naver.com")
4) winhttp(참조, vb.net)
'c:\windows\system32\winhttp.dll 참조하세요.
'imports winhttp
dim http as new winhttprequest
http.open("GET", "http://www.naver.com")
dim a as string = http.responsetext
파일 다운로드[GET]
1) inet(vb6):
Public Sub GetFileFromUrl(Byval url As String, Byval file As String)
Dim fileBytes() As Byte
Dim fileNum As Integer
On Error GoTo DownloadError
DoEvents
fileBytes() = Inet1.OpenURL(url, icByteArray)
fileNum = FreeFile
Open file For Binary Access Write As #fileNum
Put #fileNum, , fileBytes()
Close #fileNum
DownloadError:
MsgBox Err.Description
End Sub
2) webclient
'imports system.net
public sub GetFileFromUrl(byval url as string, byval file as string)
dim web as new webclient
web.downloadfile(url, file)
end sub
3) (HTTP)webrequest, (HTTP)webresponse
'imports system.net
'imports system.io
public sub GetFileFromUrl(byval url as string, byval file as string)
Dim buffer As Byte() = New Byte(LENGTH - 1) {}
Dim rcvd As Integer = 0
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim resp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim tot = resp.ContentLength
Dim stream As Stream = resp.GetResponseStream()
Dim gFS As New FileStream(file, FileMode.Create)
While 1
rcvd = 0 : Dim buff As Byte() = New Byte(LENGTH - 1) {}
rcvd = stream.Read(buff, 0, 1024)
If rcvd > 0 Then
gFS.Write(buff, 0, rcvd)
'debug.print("다운로드 중..." & math.round(gFS.length/tot*100, 0) & "% 완료[" & math.round(gFS.length/1024^2,2) & "MB/" & Math.Round(tot/1024^2,2) & "MB]"
Else
gFS.Close()
Exit While
End If
End While
'debug.print("다운 완료")
stream.Close()
resp.Close()
End Sub
end sub
'혹시나 해서 post도 올려둡니다...
[POST]로 웹에 전송
1) webclient
'imports system.net
'imports system.text.encoding
Dim web As New webclient
web.headers.add("추가할 헤더명", "속성")
dim arg as byte() = ascii.getbytes("보낼 내용-[?떼고]") '인자
dim re as byte() = web.uploaddata("보낼 주소", "POST", arg)
dim result as string = ascii.getstring(re)
2) (HTTP)webrequest, (HTTP)webresponse
'imports system.net
'imports sytstem.io
'imports system.text.encoding
Dim req As HttpWebRequest = DirectCast(WebRequest.Create("보낼 주소"), HttpWebRequest)
Dim post As String = "[?떼고 보낼 데이터]"
req.Method = "POST" : req.ContentType = "application/x-www-form-urlencoded"
Dim writer As New StreamWriter(req.GetRequestStream(), ASCII)
writer.Write(post) : writer.Close()
Dim stream As Stream = req.GetResponse().GetResponseStream()
Dim reader As New StreamReader(stream)
Dim response As String = reader.ReadToEnd
이렇게 inet 쓰지 않고도 여러가지 방법이 있습니다..
inet 보다는 vb.net에서 지원하는 클래스를 쓰시는게 바람직하겠죠?
출처- 데브피아
'프로그래밍언어 > VB.NET' 카테고리의 다른 글
VB.NET <> C# 변환 (0) | 2013.02.23 |
---|---|
URL 인코딩 (0) | 2013.02.23 |
레지스트리 세팅저장 (0) | 2013.02.21 |
핸들값 processID , processHanddle (0) | 2013.02.17 |
메모장에 텍스트 보내기 (0) | 2013.02.16 |