2010-01-14 5 views
0

서버에있는 asmx 웹 서비스에 vb.net 응용 프로그램의 데이터를 게시하려고합니다! 내가 ASMX 서비스에서이 데이터를 검색 할 수있는 방법을 이제게시물 데이터를 표시하십시오!

Public Function Post(ByVal url As String, ByVal data As String) As String 
    Dim vystup As String = Nothing 
    Try 
     'Our postvars 
     Dim buffer As Byte() = Encoding.ASCII.GetBytes(data) 
     'Initialisation, we use localhost, change if appliable 
     Dim WebReq As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest) 
     'Our method is post, otherwise the buffer (postvars) would be useless 
     WebReq.Method = "POST" 
     'We use form contentType, for the postvars. 
     WebReq.ContentType = "application/x-www-form-urlencoded" 
     'The length of the buffer (postvars) is used as contentlength. 
     WebReq.ContentLength = buffer.Length 
     'We open a stream for writing the postvars 
     Dim PostData As Stream = WebReq.GetRequestStream() 
     'Now we write, and afterwards, we close. Closing is always important! 
     PostData.Write(buffer, 0, buffer.Length) 
     PostData.Close() 
     'Get the response handle, we have no true response yet! 
     Dim WebResp As HttpWebResponse = DirectCast(WebReq.GetResponse(), HttpWebResponse) 
     'Let's show some information about the response 
     Console.WriteLine(WebResp.StatusCode) 
     Console.WriteLine(WebResp.Server) 

     'Now, we read the response (the string), and output it. 
     Dim Answer As Stream = WebResp.GetResponseStream() 
     Dim _Answer As New StreamReader(Answer) 

     'Congratulations, you just requested your first POST page, you 
     'can now start logging into most login forms, with your application 
     'Or other examples. 
     vystup = _Answer.ReadToEnd() 
    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    End Try 

    Return vystup.Trim() & vbLf 
End Function 

:이 코드를 사용하고 vb.net 응용 프로그램에서 데이터를 게시

?

+4

에 액세스 할 필요 해요 웹 형태로 그렇게 대신 POST 데이터에 변수 = XYZ를 전달하지 않는 것 같습니다,하지만 당신은 끝나지시겠습니까 질문 제목과 거의 모든 문장에 느낌표 (!)가 표시됩니까? 매우 시끄럽고 일반적으로 불쾌한 것으로 간주됩니다. 감사합니다 :) – Webleeuw

답변

0

이 코드는 일반 웹 페이지, 아마도 .Net 웹 양식 및 이 아니고 웹 서비스 인에 데이터를 게시하는 것처럼 보입니다. 웹 서비스라면 XML을 대신 전달할 것입니다. 따라서 .Net Web Form을 가정하면 Request.Form ("what-your-variable-is-called")을 사용하여 원시 POST 데이터에 액세스 할 수 있습니다. 그러나, 당신은 당신이 오프 더 레코드 원시 Request.InputStream

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Dim T As String 
    Using SR As New System.IO.StreamReader(Request.InputStream) 
     T = SR.ReadToEnd() 
    End Using 
End Sub 
+0

당신 말이 맞아요! 게시물 데이터에 대한이 코드는 적합하지 않습니다! 어디에서 asmx 웹 서비스에 vb.net 게시 데이터를 게시하고 웹 서비스 캡처 게시 데이터에 간단한 예제를 찾을 수 있습니까? – Comii

+0

다음은 Microsoft에서 제공 한 것입니다. http://support.microsoft.com/kb/301273 –

관련 문제