Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending JSON #23

Open
FilipLukac opened this issue Jul 1, 2014 · 1 comment
Open

Sending JSON #23

FilipLukac opened this issue Jul 1, 2014 · 1 comment

Comments

@FilipLukac
Copy link

Hello, I'm trying to send json object like

NSDictionary* headers = @{@"accept": @"application/json"};
NSDictionary* parameters = @{@"company_id":@"xxxx", @"type":@"nakup", @"customer_ids":@"123"};

UNIHTTPJsonResponse* response = [[UNIRest post:^(UNISimpleRequest* request) {
    [request setUrl:target];
    [request setHeaders:headers];
    [request setParameters:parameters];
    NSLog(@"%@", [request parameters]);
}] asJson];

but nothing happend... nothing is coming on my server.

I tried also

 UNIHTTPJsonResponse *response = [[UNIRest postEntity:^(UNIBodyRequest *request) {
 [request setUrl:@"http://httpbin.org/post"];
 [request setHeaders:headers];
 // Converting NSDictionary to JSON:
 [request setBody:[NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]];
}] asJson];

But nothing happend. I want to send json like:

{
company_id: val,
type: val,
.....
}

someone can help me ? am I wrong ?

@brandonramirez
Copy link

@chipsi Have you set the Content-Type header to application/json. I have found that often makes a difference. Web servers may not realize that your request body is JSON unless you tell it so via the Content-Type header. This happened on a project of mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants