Assembling SOAP Header manually with Savon - ruby-on-rails

I've been dealing with a "soap message header incorrect" error message when submiting a SOAP request using Savon.
I copy/pasted the exact same xml generated by Savon into SOAPUI and I don't get that error and I get the expected response.
So, since I'm tired of trying different things, I want to assemble my own header without Savon help on that.
What I want to do is something like:
soap.header = "<wbs:Session><wbs:SessionId></wbs:SessionId><wbs:SequenceNumber></wbs:SequenceNumber></wbs:Session>"
However I get this error from Savon:
can't convert Symbol into String
Why?
Thank you in advance.

Its likely caused by the fact you havent set any values.
I was getting this error when I had a hash containing just one custom object on return, as it was trying to access parts of the hash that had automatically been removed. (it removed unnesscary layer of hash for me :#)

I believe the header will only accept a Hash - from the savon.rb page:
Besides the body element, SOAP requests can also contain a header with
additional information. Savon sees this header as just another Hash following
the same conventions as the SOAP body Hash.
soap.header = { "SecretKey" => "secret" }

Related

Ruby on Rails basic use of RiotGames API (need explanation, solution already found)

First you must know I'm a total beginner, I'm trying to learn so I almost don't know anything.
On the basic page of the API, there is a curl command used as an example to show us how to make requests.
I'm using Ruby on Rails so I used "curl-to-ruby" website to translate it, but it did not work as expected.
I wanted it to show me this :
uri = URI.parse("REQUEST_URL")
response = JSON.parse(Net::HTTP.get(uri))
Instead I got this :
uri = URI.parse("REQUEST_URL")
response = Net:HTTP.get_response(uri)
I don't understand any of this, I thought I wouldn't need to and just use "curl-to-ruby", but apparently I really need to get this.
Would you please try to explain me ?
Or give me links ?
Or matters to read (curl, API, http) ?
Thank you very much, have a nice day.
It's because that command doesn't return just the content, it returns the whole HTTP response object including headers and body. You need to extract the response body and parse that using JSON.parse(), e.g.
JSON.parse(response.body)
See documentation here: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#method-c-get_response
(Also, there is nothing in the cURL command which would hint to the converter that the content-type of the response was expected to be JSON (e.g. perhaps an "accepts" header or something), so even if it were able to produce extra code adding the JSON.parse part, it has no way of knowing that it would be appropriate to do so in this case.)

Alamofire GET request isn't working correctly

I am sending out a GET request like so.
let parameters: Parameters = [
"filter": ["fruit": "apple"]
]
Alamofire.request(urlStr, method: .get, parameters: parameters, encoding:URLEncoding.default).responseJSON { response in
print(response.request!)
}
However, the GET request doesn't work correctly. I believe the parameters are not correct at all. This is the URL request that is printed out using the following code print(response.request!)
https://api.example.com/fruits?apiKey=1&filter%5Bfruit%5D=apple
However, using postman I can send the correct request and get the correct response using the following URL request.
https://api.example.com/fruits?apiKey=1&filter={"fruit":"apple"}
I don't know how to fix this. I tried many encoding types, but none of it worked. Any tips or suggestions are appreciated
Edit: I do get a response from the server using alamofire, but it isn't correct data because the paramters are ignored. However, the response I get from postman is correct.
Morning Curt,
Since there is no published specification for how to encode collection types, the convention of appending [] to the key for array values (foo[]=1&foo[]=2), and appending the key surrounded by square brackets for nested dictionary values (foo[bar]=baz) [is used].
In my opinion you should really avoid passing array objects in query strings. You could change your request to something like:
apiKey=1&fruit=apple
Where does presence of field fruit itself indicates response should be filtered.
Moreover:
Instead of using GET, you should consider using POST or PUT and passing values via JSON, XML, or another well-defined format. This could require server side changes obviously.
If server side is out of your control, you should consider manually encoding these parameters instead.
Source
You can find here an example of manually encoding.
Happy coding!

get GET request in Golang on fcgi

I run my scripts under Apache. I understand how I can create request, for example:
http.Get(url)
How I can get GET request? I really dont see this information in docs. Thanks in advance!
UPD
For example, i do GET or POST-request to my go script from another script. In PHP I'd just write $a=$_GET["param"]. How i can do that in Go? Sorry for bad english, by the way
Your handler is passed a Request. In that Request you find for example the parameters in the Form field as soon as you parsed it using ParseForm :
// Form contains the parsed form data, including both the URL
// field's query parameters and the POST or PUT form data.
// This field is only available after ParseForm is called.
// The HTTP client ignores Form and uses Body instead.
Form url.Values

ASP.NET WEB API 406 error:for POST request using Media format

I am very new to web api stuff:
I am getting an error
406: Not Acceptable
error message in asp.net web api rest service.
In my rest service I’m using media format for my customized XML output, to get customized output.
I’m registering my formatted media in Global.asax page.
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new mynewformat());
all my methods are post methods with typed object as parameter and parameters are accepts from body.
Whenever I try to test the service… Getting 406: Not acceptable error message.
can anyone please help me ... what could be the reason for this....???
I did notice couple of interesting points here...
If I’m commenting below line then I’m getting 200 (OK) status code (which is fine.)... but format is not applying to output.
GlobalConfiguration.Configuration.Formatters.Clear();
If i'm removing parameters in my service method.. Then its working
fine..
I request everyone.. Please guide me what could be the reason/work around/solution/fix..for this issue.
Note:I don't want accept parameters from URI so i made it to accept from frombody only.
Thanks.
There is a lot more to implementing a custom format than just adding it to the configuration formatters. It starts with having to change the media-type header to a new custom type of your choosing (like "application/myNewFormat") for all requests, for the client. On the back end, you have to implement a new MediaTypeFormatter that can handle the serialization. This involves a bit more of code.
A good example of this resides here, it can easily be stripped to boiler-plate code:
http://www.codeproject.com/Articles/559378/Implementing-Custom-Media-Formatters-in-ASP-NET-We

How to get rid of validation warnings

The complete warning is Validation (): Element 'html' occurs too few times
This is for a JSON view, which you might guess returns a JSON result and hence no html.
ASP.NET MVC has the ability to return JSON data as a proper json response. It seems you're using HTTP response which expects HTML to exist in it.
Here is an example of using JSON.NET to build a JSON ActionResult.
http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/ Here is another tutorial as well.

Resources