I can get the value in JSON format with the function:
NSMutableArray *jsonArrayClass = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
But i really have no idea how to get the string value or boolean value. we have some validation will return this data type. not JSON.
The raw value shown on Flidder looks like (ID00001 is the return string):
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 Apr 2014 17:15:28 GMT
Content-Length: 9
"ID00001"
Try this
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Related
I am trying to pass an C# object in Odatacontroler Content method:
var resp = Content(HttpStatusCode.OK, vResult );
Where vResult is a C# object with two fields (List Messaages; bool IsValidEntity) .
At client when I tried getting response bellow unexpected response coming:
Id = 0x00000003, Status = RanToCompletion, Method = "{null}", Result =
"StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content:
System.Net.Http.StringContent, Headers:\r\n{\r\n Pragma: no-cache\r\n
Cache-Control: no-cache\r\n Date: Wed, 06 Jan 2016 07:04:25 GMT\r\n
Server: Microsoft-IIS/7.5\r\n X-AspNet-Version: 4.0.30319\r\n
X-Powered-By: ASP.NET\r\n Content-Type: application/json;
odata.metadata=minimal\r\n Content-Length: 97\r\n}"
For details below can be referenced:
Odata Controller: How to convert Odata response to C# object at client
I am doing a simple post using GM_xmlhttpRequest to post some text to pastebin. This is my code
GM_xmlhttpRequest({
method: "POST",
url: "http://pastebin.com/post.php",
data: "api_dev_key=5c3***********************073a&api_option=paste&api_paste_code="+encodeURI(photo_url)+"&api_user_key=5******************************f&api_paste_name=cornered&api_paste_private=2&api_paste_expire_date=1W",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
onload: function(response) {
alert("posted " + response);
}
});
I am getting no response in the script. To check if the post request itself is working, I used http://requestmaker.com/ and it shows that the POST request is returning a 302 response
Request Headers Sent:
POST /post.php HTTP/1.1
Host: pastebin.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 152
Response Headers:
HTTP/1.1 302 Moved Temporarily
Date: Wed, 10 Dec 2014 15:27:20 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d61fd0544ec1b0c284ba908367557bc7f1418225240; expires=Thu, 10-Dec- 15 15:27:20 GMT; path=/; domain=.pastebin.com; HttpOnly
X-Powered-By: PHP/5.5.5
Set-Cookie: cookie_key=1; expires=Wed, 07-Jan-2015 15:27:20 GMT; Max-Age=2419200; path=/; domain=.pastebin.com
Set-Cookie: realuser=1; expires=Thu, 11-Dec-2014 15:27:20 GMT; Max-Age=86400; path=/
location: /index.php?e=2
Vary: Accept-Encoding
Server: cloudflare-nginx
CF-RAY: 196a7749d5c713e9-LAX
Send your request to http://pastebin.com/api/api_post.php instead of http://pastebin.com/post.php.
From all I have read gzipped response data should be automatically decompressed by the NS URL loading system. I am using AFNetworking and a AFJSONResponseSerializer to handle requests to a custom backend. I have experimented with adding "Accept-Encoding" = gzip to my request headers, but it has had no effect. My response headers include:
"Content-Encoding" = gzip;
"Content-Length" = 179837;
"Content-Type" = "application/json";
I am making the request like this:
[[AFHTTPRequestOperationManager sharedClient]
GET:#"some/endpoint"
parameters:#{#"foo":#"bar"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"Response data size %u", operation.responseData.length);
NSURL *outputURL = [[APP_DELEGATE applicationDocumentsDirectory] URLByAppendingPathComponent:#"data.gzip"];
[operation.responseData writeToURL:outputURL atomically:NO];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"ERROR [%d] [%#]", error.code, error.localizedDescription );
}];
When this runs the size of operation.responseData.length printed is what I expect. However, responseObject is nil when it should be an NSArray. I added the lines writing operation.responseData to test that the data received is what I expect. I can browse to data.gzip, uncompress it, and see my JSON.
It appears to me that the gzipped data received is not being automatically decompressed before my AFJSONResponseSerializer tries to handle it. Most of what I have found on Stackoverflow has either discussed how the decompression is automatic or suggested adding an "Accept-Encoding" = gzip header. Any suggestions would be appreciated.
Have you checked the output from the "custom backend" — use something like Charles Proxy which will let you see things like your response headers and raw content.
e.g. typical headers as shown in Charles:
HTTP/1.1 200 OK
Date Wed, 26 Nov 2014 22:25:33 GMT
Server Apache/2.2.24 (Unix) mod_hive/4.0 mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.6
X-Powered-By PHP/5.3.29
P3P CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Cache-Control no-cache
Pragma no-cache
Set-Cookie 4d3750fca133ae462ca26ca5a1cc0104=c7da991b30f53342846fff5ddaf3ea08; path=/
Cache-Control max-age=3600
Expires Wed, 26 Nov 2014 23:25:33 GMT
Host-Header 192fc2e7e50945beb8231a492d6a8024
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html; charset=utf-8
I am trying to invalidate a token but I get the following exception:
+ Headers {X-AspNetMvc-Version: 3.0
xoauth_problem: parameter_absent
xoauth_parameters_absent: oauth_session_handle&oauth_token
Connection: keep-alive
Content-Length: 165
Cache-Control: private
Content-Type: text/html; charset=utf-8
Date: Thu, 16 Aug 2012 20:03:38 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
} System.Net.WebHeaderCollection
Here is the code:
Uri url = new Uri("https://XXXYYY/OAuth/InvalidateToken");
string oauthHeader = "OAuth oauth_session_handle="AAA3D&",oauth_token="SDSFSDSDF%3D",oauth_consumer_key="5512CONSUMER",oauth_nonce="0000012145o",oauth_signature="QEESIGN99$",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1345141023",oauth_version="1.0"";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
webReq.Method = WebRequestMethods.Http.Get;
webReq.Headers.Add(HttpRequestHeader.Authorization, oauthHeader);
WebResponse response = webReq.GetResponse();
Please note I do have parameters
I'm sending request to the server and I'm getting the html response. But
I want to store the cookie information. Is there any other classes or methods
available to get the cookie information in blackberry.
for (int j = 0; j < 20; j++) {
String key = httpConn.getHeaderFieldKey(j);
String field = httpConn.getHeaderField(j);
if (key == null && j > 0) {
break;
}
add(new RichTextField(key + " : " + field));
}
I used this code to get the header information, but I didnt get-setcookie header ( which I'm supposed to get). the output is as follows.
Connection: Close
expires: -1
date: Tue, 08 Mar 2011..........
server: Microsoft-IIS/7.5
x-powered-by: ASP.NET
pragma:no-cache
x-rim-etag:4626353C5B58791ACD00D30EAADEAF4663FE219F
cache-control: no-cache, no-store
x-aspnet-version:2.0.50727
content-location:http://beemediahive...........
content-type: text/html; charset=utf-8
How do I get cookie information in blackberry?
check out below link:
http://esgroupmobile.wordpress.com/2009/05/29/blackberry-development-tip-http-get/
Hope it helps you.