POST XML example?

667 views
Skip to first unread message

Cody

unread,
Jan 24, 2012, 8:50:57 PM1/24/12
to RestKit
Hi all,

I'm having a hard time finding a clean example on how to POST a
parameter that contains pure XML. At this stage I'm not sure if it's
my code or the server expecting something different. If I were to post
XML as a parameter, is the code correct? I'm working against Jive's
REST API.

Code:

- (void)sendRequest
{
// Grab the singleton RestKIT client
RKClient *singleClient = [RKClient sharedClient];

NSString *filterXML = [NSString stringWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"testBlog" ofType:@"xml"]
encoding:NSUTF8StringEncoding error:nil];

// send the data
if (!error)
[singleClient post:@"/rpc/rest/blogService/
blogsPostsWithFilter" params:[RKRequestSerialization
serializationWithData:[filterXML
dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeXML]
delegate:self];
}

XML:
<?xml version="1.0" encoding="utf-8" ?>
<getBlogPosts>
<filter>
<numResults>5</numResults>
<tags>running</tags>
</filter>
</getBlogPosts>

Error:
An appropriate representation of the requested resource /cs/rpc/rest/
blogService/blogsPostsWithFilter could not be found on this server.

Shane Zatezalo

unread,
Jan 24, 2012, 9:14:07 PM1/24/12
to res...@googlegroups.com
Can you use a bash or curl script to do a POST of your XML to the server at that URL?

A "grep -ie 'appropriate representation' * -r" or Restkit show's no match for that error.

If I were you I'd get a curl command posting to it correctly first, then go from there.

Shane

Blake Watters

unread,
Jan 24, 2012, 11:35:49 PM1/24/12
to res...@googlegroups.com
Cody -

Your snippet should fire the request as you intend. You may want to turn up the logging level using RKLogConfigureByName("RestKit/Network", RKLogLevelTrace); to get a better view of what's happening within RK.

--
Blake Watters
VP Engineering, GateGuru
Mobile: 919.260.3783
Get GateGuru for iOS: bit.ly/ggitunes
Get GateGuru for Android: bit.ly/ggandroid

Cody

unread,
Jan 25, 2012, 12:41:43 AM1/25/12
to RestKit
Thanks for your help (both of you)...

I'll try both methods tomorrow when I get back to work and be sure to
continue this discussion as I think it will help anyone in the future
that may need to connect RestKit to Jive's REST API.

Cody

unread,
Jan 25, 2012, 5:35:57 PM1/25/12
to RestKit
Going down the curl path hasn't helped me much.

Because I'm not sure if it's because I'm dealing with https or don't
have the correct flag to deal with their reply, i'm getting something
like:

curl -X POST -v -H 'Content-type: text/xml' --user
tempUsername:tempPassword -d
'file=<getBlogPosts><filter><tags>test_tag</tags></filter></
getBlogPosts>' https://xxxxx.com/rpc/rest/blogService/blogs

* About to connect() to xxxxx.com port 443 (#0)
* Trying 11.11.11.11.. connected
* Connected to xxxxx.com (11.11.11.11) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
* subject: C=US;
* ###### CERTIFICATE INFORMATION ######
* start date: 2011-10-07 17:53:00 GMT
* SSL certificate verify ok.
* Server auth using Basic with user 'cody...@xxx.com'
> POST /rpc/rest/blogService/blogsPostsWithFilter HTTP/1.1
> Authorization: Basic Y29keS5nYXJ2aW5Adm
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
> Host: xxxxx.com
> Accept: */*
> Content-type: text/xml
> Content-Length: 71
>
< HTTP/1.1 406 Not Acceptable
< Content-Encoding: gzip
< Content-Length: 235
< Content-Type: text/html; charset=iso-8859-1
< Date: Wed, 25 Jan 2012 22:21:00 GMT
< Connection: close
<
]?MO?0
???fw??(?X;1i?J???#?B?O?ݸ???Xܴ????w?<??:v??E<t??ګs?? v??l??//?
%e?Ž=ɇ?#?"?VkJ?FO?N#pI?1?߹|'??Ԉ$?TJ9??dJ?




Even a simple -x GET delivers gibberish. Any idea why?

Going to check out REST logging level now.

Cody

unread,
Jan 25, 2012, 5:51:38 PM1/25/12
to RestKit
I'm starting to think it's not being called correctly.

Here is my dump using RKLogConfigureByName("RestKit/Network",
RKLogLevelTrace);...

2012-01-25 14:44:30.287 TestACX[10487:207] D
restkit.network:RKClient.m:389 Reachability to host '0.0.0.0'
determined for client <RKClient: 0x8c44a60>, unsuspending queue
<RKRequestQueue: 0x8c469c0 name=(null) suspended=YES requestCount=0
loadingCount=0/5>
2012-01-25 14:44:32.760 TestACX[10487:207] Filter XML: <?xml
version="1.0" encoding="utf-8" ?>
<getBlogPosts>
<filter>
<tags>test_tag</tags>
</filter>
</getBlogPosts>
2012-01-25 14:44:32.763 TestACX[10487:207] D
restkit.network:RKRequest.m:362 Sending asynchronous POST request to
URL https://xxxxx.com/cs/rpc/rest/blogService/blogsPostsWithFilter.
2012-01-25 14:44:32.765 TestACX[10487:207] T
restkit.network:RKRequest.m:310 Prepared POST URLRequest
'<NSMutableURLRequest https://xxxxx.com/cs/rpc/rest/blogService/blogsPostsWithFilter>'.
HTTP Headers: {
Authorization = "Basic
Y29keS5nYXJ2aW5Adml6d2Vya3MuY29tOlZpendlcmtzMjI0MA==";
"Content-Length" = 982;
"Content-Type" = "application/xml";
}. HTTP Body: <?xml version="1.0" encoding="utf-8" ?>
<getBlogPosts>
<filter>
<tags>test_tag</tags>
</filter>
</getBlogPosts>.
2012-01-25 14:44:33.049 TestACX[10487:207] D
restkit.network:RKResponse.m:163 Asked if
canAuthenticateAgainstProtectionSpace: with authenticationMethod =
NSURLAuthenticationMethodServerTrust
2012-01-25 14:44:33.216 TestACX[10487:207] D
restkit.network:RKResponse.m:196 NSHTTPURLResponse Status Code: 406
2012-01-25 14:44:33.217 TestACX[10487:207] D
restkit.network:RKResponse.m:197 Headers: {
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 235;
"Content-Type" = "text/html; charset=iso-8859-1";
Date = "Wed, 25 Jan 2012 22:44:33 GMT";
Vary = "Accept-Encoding";
}
2012-01-25 14:44:33.218 TestACX[10487:207] T
restkit.network:RKResponse.m:202 Read response body: <!DOCTYPE HTML
PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /cs/rpc/
rest/blogService/blogsPostsWithFilter could not be found on this
server.</p>
</body></html>
2012-01-25 14:44:33.218 TestACX[10487:207] I
restkit.network:RKRequest.m:562 Status Code: 406
2012-01-25 14:44:33.219 TestACX[10487:207] I
restkit.network:RKRequest.m:563 Body: <!DOCTYPE HTML PUBLIC "-//IETF//
DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /cs/rpc/
rest/blogService/blogsPostsWithFilter could not be found on this
server.</p>
</body></html>
2012-01-25 14:44:33.220 TestACX[10487:207] Got a response from the
server: 406
2012-01-25 14:44:33.221 TestACX[10487:207] Content type: text/html;
charset=iso-8859-1
2012-01-25 14:44:33.222 TestACX[10487:207] Unknown: <!DOCTYPE HTML
PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /cs/rpc/
rest/blogService/blogsPostsWithFilter could not be found on this
server.</p>
</body></html>

Cody

unread,
Jan 25, 2012, 5:56:41 PM1/25/12
to RestKit
I feel like I need to associate the XML with a "filter" keyword
according to the documentation. Not really sure how to do that using
RESTKit.

Reference from the Jive API of what I'm trying to call:

-------------------------------------------
Get blog posts

Returns all the blog posts that match the criteria specified by the
filter. The filter provides a way to specify blog post characteristics
that constrain the results you receive.
POST http://domain:port/application_context/rpc/rest/blogService/blogsPostsWithFilter
Query Parameters

Name Type Description
filter Contents of BlogPostResultFilter A filter with
criteria to constrain the list of blog posts.


Parameter XML Payload Template

<getBlogPosts>
<filter>
<!-- Contents of BlogPostResultFilter -->
<filter>
</getBlogPosts>




Response

List of BlogPost All the blog posts that match the filter.
Response XML Payload Template

<getBlogPostsResponse>
<!-- List of ... -->
<return>
<!-- Contents of BlogPost -->
<return>
</getBlogPostsResponse>

Cody

unread,
Jan 27, 2012, 6:06:49 PM1/27/12
to RestKit
For anyone following this...

This ended up being an SSL configuration issue with the server. Though
I'm running into a more specific API issue with Jive now, I'm actually
getting through using RestKit.

Thanks for your input earlier, as this was helpful enough for me to
know this is how XML is submitted via a POST and that's the most
important thing to take away from this thread.

Cody

unread,
Jan 27, 2012, 6:47:30 PM1/27/12
to RestKit
So the story gets a bit deeper.

I'm able to do REST calls to the url using FireFox REST Client and
Google Chrom's Rest Console 4.0.2, but I can't do it through RESTKit.
Any ideas with that?

Jonathan Hoskin

unread,
Jan 27, 2012, 7:15:52 PM1/27/12
to res...@googlegroups.com
Have you tried using a debugging proxy to see what the differences are, going over the wire?

More info here:


-- 
Jonathan Hoskin
Sent with Sparrow

Cody

unread,
Jan 30, 2012, 2:18:07 PM1/30/12
to RestKit
Hi, thanks for the tip using Charles!!

Testing it didn't get me very far. I think part of the problem is
something with server communication using SSL. When using Charles, it
doesn't give me information using HTTPS because everything is
encrypted, just that it went through basically. When I enable the
HTTPS proxy, I don't ever get a reply to look at raw text headers /
response.

It's odd, just about every REST client fails for me except for
Firefox's REST add-on. They all get the same 406 error.

- Cody

On Jan 27, 4:15 pm, Jonathan Hoskin <jonat...@hosk.in> wrote:
> Have you tried using a debugging proxy to see what the differences are, going over the wire?
>
> More info here:http://groups.google.com/group/restkit/msg/9852132e6ba9632d
>
> --
> Jonathan Hoskin
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

Jonathan Hoskin

unread,
Jan 30, 2012, 2:33:08 PM1/30/12
to res...@googlegroups.com
If you want to use SSL through Charles you'll need to add Charles' own CA Certificate to your device. And you cannot do this on the simulator.

To add Charle's SSL cert to your device:


2. Unzip it and put the file (charles-proxy-ssl-proxying-certificate.crt) on a web server (or email it to your device). 

3. Point Mobile Safari at the URL for the above file (or open it in mail).

4. iOS will detect that it is a certificate file and offer to add it to the local certificate store.


You can also do this with an iOS configuration profile, I just find the way above a bit quicker.


-- 
Jonathan Hoskin
Sent with Sparrow

Cody

unread,
Jan 30, 2012, 2:53:05 PM1/30/12
to RestKit
Thanks. It looks like a proxy issue with the server set up. I'll
update this thread and let you guys know the outcome.

Charles helps. I like this app quite a bit, going to buy it :)

Thanks again

Cody

unread,
Jan 30, 2012, 8:35:06 PM1/30/12
to RestKit
Hi all

Just wanted to mention that the problems that were coming up was from
the firewall not being set up to accept POST calls to the REST API on
Jive.

If you get a 406 error through https, may want to talk to the system
admin of your server :)

Thanks everyone for your help, mission accomplished.
Reply all
Reply to author
Forward
0 new messages