Giter Site home page Giter Site logo

Custom Username Header about restclient HOT 25 CLOSED

SeanLintern avatar SeanLintern commented on September 28, 2024
Custom Username Header

from restclient.

Comments (25)

johnclayton avatar johnclayton commented on September 28, 2024

Hey criosist, I'll add a test case and see if I can track down what you're seeing. How are you logging out the headers after you set up the resource?

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Sorry i made a mistake and didn't realise that my username was in fact NULL and the rest client was removing it for a good reason, sorry again.]

On 3 Oct 2012, at 18:00, John Clayton wrote:

Hey criosist, I'll add a test case and see if I can track down what you're seeing. How are you logging out the headers after you set up the resource?


Reply to this email directly or view it on GitHub.

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

Ah, well good to know it was handling nil header values properly then ;-) Feel free to file issues for anything else you notice.

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Just enquiring really, but at the moment i am making a post request via adding the things i need to an array, and then adding those to a string via:

//Request Vars for /Json/GetNodeCubeData
NSMutableArray *testQuery = [[NSMutableArray alloc]init];
[testQuery addObject:[NSString stringWithFormat:@""NodeId":%@,",nodeID]];
[testQuery addObject:[NSString stringWithFormat:@""UnitId":%@,",unitID]];
[testQuery addObject:[NSString stringWithFormat:@""DataAggregation":%@,",dataAggregation]];
[testQuery addObject:[NSString stringWithFormat:@""DateAggregation":%@,",dateAggregation]];
[testQuery addObject:[NSString stringWithFormat:@""DateFrom":%@,",dateFrom]];
[testQuery addObject:[NSString stringWithFormat:@""DateTo":%@",dateTo]];
[testQuery addObject:[NSString stringWithFormat:@"}]}"]];

payload = [NSString stringWithFormat:@"{"Items":[{%@",[testQuery componentsJoinedByString:@""]];
NSLog(@"Payload: %@",payload);

Is there a better way to make these requests ?

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

If what I think you are attempting is correct—you want to send a collection of name:value pairs to your endpoint as JSON—then yes, there is an easier way.

RESTClient automatically encodes/decodes objects for you depending on the content type. You can take a look at the implementations of <RCCoder> to see how it works, but basically, if "json" is matched in the content type header the request will take any supplied payload and turn it into JSON if it can.

So you could do it like this:

RCResource *myResource = [site resource:@"items"];
NSDictionary *payload = @{ items : @[ @{ @"foo": @"bar" } ] };
[myResource post:payload withCompletionBlock:^(RCResponse *response) {
    if (response.success) {
          ..
    }
}];

The README has a few examples of passing in objects that get coded using various heuristics if you want to check out more. Also, you can take a look at the specs as they have examples of doing certain common tasks.

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

I should also note, there are some convenience methods for setting content/accepts types, via resource.contentType = RESTClientContentType<FOO>, but they are also guessed from the types of objects being sent/received and things like filename extensions.

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Thank You :D

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

Glad to help

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Hey, is there any way to see what i am sending to the server ? i have tried:

RCResource *posts = [site resource:@"/Json/GetNodes"];

[posts getWithCompletionBlock:^(RCResponse *response)
 {
     responseResult = response.result;
     NSLog(@"Sent: %@",posts.requests);

     NSLog(@"Response: %@",responseResult);
}

And i get the response but i would like to see the difference between what i send during a POST and GET ? .requests shows the ID and URL of request but i would like to see the actual payload/query ?

Thanks

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

There are a couple of ways you can get information about the request. You could install a preflight block on the resource which will run just before the request is started and gives you a chance to abort the request and/or inspect it before it is sent. Or, you can simply ask the response for its request in your completion block: response.request.payload, for example. Or, response.request.responseBody to get a string representation of the response data.

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Hmmm if i use payload i get a NULL in both response.request.payload and if i set up a preflight block i can get other info like headers and request but not payload :/

I am logging it with %@ this is correct ?

Thanks

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

And you are doing the post via one of the post.. methods, not the get method above, yes?

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Sorry i just realised i am but using query:(id) so i guess with GET the URL to be sent will just be my regular URL?

if so no matter what i put in query i get: "Expected Expression" error, i am tryign to just place a String in the as the query :/

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

I have a post method which is working fine and am trying to work on my GET methods with query

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

Ok, so payload will never be set for a GET request, doing a get with a query will actually append the query to the URL for that particular request. If there is a specific query you are trying that is failing, send it over and we can add a test case to see what's up.

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Its not the query, its just that when trying to use:

[posts getWithCompletionBlock:^(RCResponse *response) query:myString {

i get an error on query:myString as expected expression :/

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

If that's the actual syntax you are using, you've interjected the query argument inside the block definition. It should be something like this:

[posts getWithCompletionBlock:^(RCResponse *response){...} query:myString];

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Ah thank you that works perfect

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

np

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

I am a little amateur when it comes to web services, but as far as i understand the query is the part after the call i.e. service/json/myCall?Query=this&Query2=that
?
but if i use a string i get an error and if i use an array i get a null response, which makes me think it isnt sending correctly

from restclient.

johnclayton avatar johnclayton commented on September 28, 2024

Sorry, query is either an array or dictionary. See the documentation in the RCResource header for an explanation of the differences. You probably just want a dictionary.

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Hey, i just moved some files and am now getting this error:

Undefined symbols for architecture armv7:
"OBJC_CLASS$_RCResource", referenced from:
objc-class-ref in nodeTable.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

all files in my project are there, i.e. they do not have red names implying they are missing but i did remove the project then re-add it to my project and then this error happened...

Any ideas ?

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

It seems that when i expanded frameworks folder inside RestClient some of the frameworks are missing, and i cant seem to find them :/

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Hmm i removed the project and re-added it and they are still red but the error has gone instead now i have cannot find xyz.h and have to add all DIRs manually to paths :/

from restclient.

SeanLintern avatar SeanLintern commented on September 28, 2024

Ok now it is complaining about the missing libraries:

"library not found for -lCorePlot-CocoaTouch"

any idea ?

thanks

from restclient.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.