POST Command Problem

246 views
Skip to first unread message

Dave@Appsellerate

unread,
Dec 2, 2012, 10:03:36 AM12/2/12
to rest...@googlegroups.com

I am attempting to call a REST web service running on an Apache Tomcat web server using the RestSharp object.

 

The following cURL command executes sucessfully and delivers the requested output”

 

curl http://local:8080/rest-service/report/export/xml -u username:password -F xmlRequest=@D:\ Request.xml -o D:\ Report.xml

  

The contents of the Request.xml file is:


<?xml version="1.0" encoding="UTF-8"?>

<request

xmlns="http://www.blancco.com"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.blancco.com service-request.xsd">

    <export-report>

        <search path="user_data.fields.extra2.value" value="VA4791-22" operator="eq" datatype="string" conjunction="true" />

    </export-report>

</request>

 

I am using the following code to call the REST service from .NET using the RestSharp object

 

    Public Shared Sub RestSharpExample()

 

        Const username As String = "username"

        Const password As String = "password"

        Const uri As String = "http://local:8080/rest-service/report/export/xml"

 

        Dim content As String = _

            "<?xml version=""1.0"" encoding=""UTF-8""?>" & Environment.NewLine & _

            "<request" & Environment.NewLine & _

            "xmlns=""http://www.blancco.com""" & Environment.NewLine & _

            "xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" & Environment.NewLine & _

            "xsi:schemaLocation=""http://www.blancco.com service-request.xsd"" > " & Environment.NewLine & _

            "    <export-report>" & Environment.NewLine & _

            "        <search path=""user_data.fields.extra2.value"" value=""VA4791-22"" operator=""eqxx"" datatype=""string"" conjunction=""true"" />" & Environment.NewLine & _

            "    </export-report>" & Environment.NewLine & _

            "</request>"

        Dim buffer As Byte() = Encoding.ASCII.GetBytes(content)

 

        Dim client As New RestSharp.RestClient(uri)

        client.Authenticator = New RestSharp.HttpBasicAuthenticator(username, password)

        Dim request As New RestSharp.RestRequest(RestSharp.Method.POST)

        request.AddFile("xmlRequest", buffer, "application/xml")

 

        Dim response As RestSharp.IRestResponse = client.Execute(request)

        Console.WriteLine(response.ResponseStatus)

        Dim responseContent As String = response.Content

        Console.WriteLine(responseContent)

 

    End Sub

  

The following occurs when calling the service:

response.Content = "MC_EXPORT_REPORT_FAILED null "

StatusCode = “BadRequest {400}“

 

In debugging I have done the following:

 

if I change the value attribute of the search element of the xmlRequest file to a nonexistent value, I get the following response:

response.Content ="MC_EXPORT_REPORT_FAILED NO REPORTS FOUND”

StatusCode = “BadRequest {400}“

 

if I change the operator attribute of the search element of the xmlRequest file to an invalid value, I get the following response:

response.Content = "MC_EXPORT_REPORT_FAILED_NOT_VALID_REQUEST Not a valid request file compared to xsd! string value 'eqxx' is not a valid enumeration value for type of operator attribute in searchType in namespace http://www.blancco.com

StatusCode = “BadRequest {400}“

 

The server appears to be receiving the xmlRequest properly, but is not returning the report in the restSharp reponse. The "MC_EXPORT_REPORT_FAILED null " response does not provide any information about the error.

Is my translation of the cURL command into RestSharp accurate? What else can I check?

 

Thanks,

Dave

Reply all
Reply to author
Forward
0 new messages