사용자가 URL 인코딩 된 쿼리 문자열로 전체 URL을 입력하고 웹에 보내는 프로그램이 있습니다. 내가 vb2005에서 HttpWebRequest를 사용하고httpwebrequest 콘텐츠 길이 vb2005 받기
는
나는 같이 URL이 I should send a content length
경우 http://www.someurl.com/query.php?q=somtext¶m1=paramtext¶m2=paramtext2
가 어떻게 URL에서 컨텐츠 길이를 얻는 것을 말하는 웹 사이트에서 오류가 발생 이걸 자동으로 알 수있는 방법이 없나요? 내가 이것을 사용하기로 결정
편집이 올바른
Private Function GetHtmlFromUrl(ByVal url As String, _
Optional ByVal PostData As String = vbNullString) As String
If url.ToString() = vbNullString Then
Throw New ArgumentNullException("url", "Parameter is null or empty")
End If
Dim html As String = vbNullString
Dim myUrl As New System.Uri(url)
Dim request As HttpWebRequest = WebRequest.Create(url)
With request
.ContentType = "Content-Type: application/x-www-form-urlencoded"
.Method = "POST"
.UserAgent = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.1)"
.Referer = "http://www.google.com"
.ContentLength = myUrl.Query.Length
End With
Try
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
html = Trim$(reader.ReadToEnd)
Return html
Catch ex As WebException
Return ex.Message
End Try
End Function
는, 내 오류를'같은 일이 내가 그 코드 – Smith
@Smith를 사용할 때 발생 error' 500 internat에 서버를 제공합니다 요구 스트림 코드에서 GET 요청을 수행 중이지만 POST 요청임을 나타냅니다. 더 조심스럽게 링크 된 기사를 살펴보십시오.하지만 먼저 문제의 웹 사이트가보고 싶은 방법 (GET 또는 POST)을 확인해야합니다. – Tergiver