iPhone - How to post and get xml data to server? - ios

I want to get xml string from url "http://test.php?value=xxx",here xxx shall be in XML format,for example:<request><command>test</command></request>.After I post this,the server will give me a result with xml string.But i don't know how to do that.Anyone has a solution?Thanks.

http://www.raywenderlich.com/30445/afnetworking-crash-course
That website gives you a step by step exactly what you need with AFNetworking. The question you are asking is very vague. If you get more specific then I can give direct code. Otherwise that crash course website is very informative.

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.)

Angular 2 - upload of file

I need to create upload of images to my webserver in my Angular 2 app. Can anybody provide me some guidance how to achive this?
These are the prerequisities:
ASMX web service communicating in JSON.
post method used for communication.
JPEG / PNG up to 1MB of size.
Concept I wanted to follow (but failed)
Load the content of JPEG to variable, encode it using the Base64 coding and post it to ASMX service that will accept two parameters (token for authentication and encoded data.
What exactly is my problem
Web service was the easy part, it is done and working, but I can't manage to get the file content for enconding. I used this:
component.html
...
<input type="file" (change)="fileChangeEvent($event)" />
...
component.ts
private fileChangeEvent(fileInput: any) {
let image = fileInput.target.files[0] as File;
...
}
As you have probably guessed, the problem is in the File class, because it provides me only basic info about the file (name, size, last modif, ...) but I can't get the content of the file. Or at least I don't know how to get it. I also checked other questions here on SO, but all of the answers had something special that did not met my requirements. And maybe I'm just blind, but I can't see where the content is get.
So, is there anybody, who is able to provide me some guidelines to follow?
Thank you very much in advance.
I have left this question open for experienced guys, who could be able to answer it. There is no answer though and I found out the answer yesterday. So, after some research and modification of search phrase, I found out the answer. There is a FileReader type which can be used for reading the content of the file. Here is the source of the answer:
Getting byte array through input type = file
Thanks to original answer now I know how to do it.

How to upload an image file using Rest Assured framework?

I am trying to upload a file using the rest assured framework. The call is a POST call on the API that i am using and the code is mentioned below:
given()
.contentType("image/jpg")
.accept("application/json")
.auth().oauth2(accessToken, OAuthSignature.QUERY_STRING)
.multiPart(new File("C:/Snap0000.jpg"))
.post("/objects/files")
.getBody();
The error that I get when doing this is:
400 - Unable to read image info Couldn't read magic numbers to guess format.
What am I doing wrong?
You may be missing the control name for the multipart? See javadoc for the multiPart method or look at the documentation.
Edit: above link is (partially) broken; this one at github seems to work better: https://github.com/rest-assured/rest-assured/wiki/Usage#multi-part-form-data

How URL works? And what is the relation with GET and POST?

I have question, basic question I guess. But its important for me to learn more about web application.
I've ever seen a url with there are other words. for example:
http://api.openweathermap.org/data/2.5/weather?q=Setapak&mode=xml
there is q=setapak&mode=xml. what it means?
and what relationship with GET or POST?
when I try to create a simple page such which the code are:
<?lc
put $_GET['number'] into number
put number
?>
and I run the url on the browser: livecode/nana/url.lc?number=1
it shows nothing. So I get confuse. Can anyone explain to me?
Thank you..
Get will transfer you Parameter Using URL
all parameters will add to the URL ?number=1 this is one such example. it will carry number variable with value 1.
Post transfer parameters by attaching them to HTTP message body. Refer below link and you can get a good understanding about that.
http://www.w3schools.com/tags/ref_httpmethods.asp
You can't use single quotes in LC. use normal quotes around "number", and it should work.

JSoup does not post data in ISO 8859 encoding

Is there any way to tell JSoup to post data using iso-8859-1 rather than utf-8 ?
I tried posting a parameter that contains the letter 'è' the my webserver receives the character with hex code C3A8 but I want to send E8.
The code I wrote is
Document document = Jsoup.connect("https://somesite.com/test") .data("parameter1","\u00E8").
header("Content-Type","application/x-www-form-urlencoded;charset=UTF-8")
.method(Method.POST)
.execute()
.parse();
As already said, on the other hand I get a 2 bytes data (C3A8) rather than a single byte with E8 inside.
Thanks in advance for your help.
Trying to replicate a successful POST request with JSoup - data posted to server does not get decoded
Has an accepted answer, saying it is not possible to do it. You will have to find a way to post your code into utf-8. If you do not succeed in that, just open a new question about it.

Resources