简体   繁体   English

.Net RESTful Web服务:发送xml文件

[英].Net RESTful Web Service: sending xml file

I'm trying to send an xml file containing a list of files to a restful webservices. 我正在尝试将包含文件列表的xml文件发送到一个宁静的Web服务。 It 'a project in vb.net. 这是vb.net中的一个项目。 The function that passes the data to the web services is the following: 将数据传递到Web服务的功能如下:

 Private Function SendActivityToWEBSERVICE(ByVal xmlFile As String) As Boolean
    Try
        sUri = "http://localhost:35299/LiveUpdateWS/SincronizzaAttivita?d=" + xmlFile.ToString()

        Dim req As HttpWebRequest = WebRequest.Create(sUri.ToString())
        req.Method = "GET"  
        req.KeepAlive = False

        Dim response As HttpWebResponse = req.GetResponse()
        Try
            Dim xmlDoc As New Xml.XmlDocument
            xmlDoc.Load(response.GetResponseStream())

        Catch exc As XmlException
            Console.WriteLine("Eccezione " + exc.Message)
            Return False
        End Try

    Catch ex As Exception
        Console.WriteLine("Eccezione " + ex.Message)
        Return False
    End Try
    Return True
End Function

The interface of web services is as follows: Web服务的界面如下:

<OperationContract>
<WebGet(UriTemplate:="SincronizzaAttivita?d={sXMLFile}")>
Function SaveDataPost(sXMLFile As String) As Boolean

If the xml file that I am sending is of small size everything works fine. 如果我发送的xml文件很小,则一切正常。 If I try to send large files I get the error 404.15. 如果我尝试发送大文件,则会收到错误404.15。 I saw that to send strings or data of a certain size to a web services is recommended to use POST instead of GET. 我看到建议将一定大小的字符串或数据发送到Web服务建议使用POST而不是GET。 To me it is unclear how to modify the above code to do it, always that this is the solution to my problem. 对我来说,目前尚不清楚如何修改上面的代码来做到这一点,始终是这是我的问题的解决方案。 Can you tell me what and how to change the code? 您能告诉我什么以及如何更改代码吗?

You just need to use post method instead of GET req.Method = "POST" 您只需要使用post方法而不是GET req.Method =“ POST”

and send the data in separate variable instead of query parameter. 并以单独的变量而不是查询参数发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM