POST request from iPhone to Django - iphone

I'm trying to send a POST request from iPhone to Django, but for some reason I can't. The request is sent, but the server doesn't receive it properly.
What is the regular expression that accepts POST? In my case, I use this one: /messages/a/s=person1&r=person2&c=hello/.
How do I retrieve the POST arguments in the Django view? request.POST['s'] should work?
Thanks.

POST parameters are not part of the URL, so your regex should simply detail the main part of the url you want to receive it on. To take your example, change it to /messages/a/. Then, in your "messages" app, have a view/function called a: that one will be reached on receiving any POST (or GET, which you're currently (almost) depicting in your url) to that location.
The arguments can then indeed be retrieved using request.POST['keyname']. To make things more convenient, supply a default value when getting the data so you need less error checking: request.POST.get('keyname', None). This will get the value of keyname when available, or None otherwise.
The posting itself... depends on more code then you're currently showing. Can't say anything about that with your current question.

That URL you've pasted in will pass the data through the request.GET dictionary. If you want to change your iPhone app to POST data, you'll have to share your code.

Related

Unknown number of Parameters in GET request: Play Framework 2.3.x+ Twilio

I am trying to point my twilio voice URl to my server.
So my routes files has this line:
GET /v1/twilio/ controllers.Application.call()
When I get the request from Twili, I get it as below:
/v1/twilio/?AccountSid=someRandomSID&
ToZip=0000&
FromState=A&
Called=%2B109213098234&
FromCountry=US&
CallerCountry=US&
CalledZip=9000&
Direction=inbound&
FromCity=xyz&
CalledCountry=US&
CallerState=A&
CallSid=randomSID&
CalledState=A&
From=%2B123455667&
CallerZip=90909&
FromZip=9890&
CallStatus=ringing&
ToCity=BLA&
ToState=AA&
To=%2B765213765&
ToCountry=PQR&
CallerCity=PT&
ApiVersion=2010-04-01&
Caller=%23123213&
CalledCity=BB]
SO you see, there are a lot of parameters.
My problem is that I am Not aware of all the parameters.
So when I just put above line in my routes file, I get an Error: 404 Not found.
How should modify the routes file so that I get the GET request?
If I ask twilio to send me POST request, then I don't have to worry about it as then I can simply get the parameter I need by Querying thee RequestData.
But there has to be some way I can get GET REQUEST to succed and reach my application controller.
Please help me here.
sorry if this is a silly question. But I am really struggling to get some info.
PS: I am using 2.3X version of play framework
Also, I dont have the control over parameters sent by Twilio.
I will simply get a GET/POst request, as per this : https://www.twilio.com/docs/api/twiml/twilio_request#synchronous
There's nothing unusual with this route, it works with sample URL like a charm (checked) maybe Twilio untrails return path by default? try to add spare route for handling this case as well:
GET /v1/twilio controllers.Application.call()
GET /v1/twilio/ controllers.Application.call()

Facebook graph api function - empty response

im currently working on facebook integration into my mobile AS3 game. I'am downloading friends pictures, which works just fine and is not currently an issue. Problem is, i am trying to detect, if user has silhouette (default) picture or his own (is_silhouette property);
Here goes code:
(response[i].id) is valid user id which i have got from previous api comunication
...
HasDefault(response[i].id);
...
private function HasDefault(uid:int):void{
FacebookMobile.api("/"+uid+"/picture", callbackX);
}
private function callbackX(response:Object,fail:Object):void{
if (response != null){
trace(response.url);
trace(response.is_silhouette);
}else{
trace("here goes nothing...");
}
first things first...this code above has 2 issues. First problem is, unless i use absolute URL, facebook does not respond, so API method has actually look like this:
FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);
i dont know why i have to use absolute url here, because anywhere else id/function is good enough...but that is not still main problem.
If i use absolute URL i do get valid response from facebook but according to this https://developers.facebook.com/docs/reference/api/using-pictures/ i should get response.url and response.is_silhouette in my response object. i however recieve only empty response object...I'am starting to be realy desperate.
In addition, i have tried to paste THE SAME request into the https://developers.facebook.com/tools/explorer explorer and surprise surprise...it returns
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc1/somenumbers.jpg",
"is_silhouette": false
}
}
...which is exactly what i need...but within the application i get only empty response object...
I do not know what you line "FacebookMobile.api("https://graph.facebook.com/"+uid+"/picture", callbackX);" does.
But whatever library that is, stop using it, because its not letting you specify the call you want to make. You can just call the graph api calls yourself using a URLLoader.
So here is the magical thing that is going wrong: You need to be able to append an extra variable when you request the picture: "?redirect=false"
This tells facebook to give you a json response. If you do not have that variable, you will get a redirect to the actual image, which is usually what a person wants anyway.
To see how that works, test out the two links below, one with redirect=false - which you want. and One with it set to true - which you do not.
https://graph.facebook.com/shaverm/picture?redirect=false
https://graph.facebook.com/shaverm/picture?redirect=true
I am pretty sure what is happening is that you are getting the image back instead of the json response describing the image.

Simplest example for sending post data via links in Zend Framework

Starting with Zend and I´d like to know what is the simplest way of sending POST data to another page, not by forms, but by some link in my view instead. Thanks :)
You can't send POST data through a link. At least not through a normal link. Link can only carry GET data.
If you need to send POST over a link it's most certainly a design flaw.
If you're 100% sure, that you need it, you can do that using jQuery and onclick event. It`s not possible to do it without javascript. Other option would be to send it using form with hidden fields with single submit button visible - that would even work without javascript.
Normal hyperlinks in HTML are sent with GET requests and are not supposed to change the state of the resource being accessed. This is known as being idempotent. You can repeat the request over and over, and the result of each succeeding request to the same URL is the same as the first one.
POST requests don't have this restriction and are intended for when the user needs to change something (such as creating a new resource.)
It's not possible to send a POST request via a normal HTML link. And even if you find a way, it breaks an almost universal expectation that web users have. What are you trying to accomplish? Maybe there's a better way.
But to answer your question, you could use something like jQuery to capture the "click" event and make it do a POST request:
$('.my-link').click(function() {
var url = $(this).attr('href');
var data = {};
$.post(url, data, function() {
window.alert('success!');
});
return false;
});
If your URL has any query parameters, i.e. "?foo=bar&baz=bum", then you'd probably need to strip them off of the URL and pass them as a second parameter to the $.post() function. This is left as an exercise for the reader. ;-)

Twitter API : Decode string returned by getFollowerIDsFor from Twitter (MGTwitterEngine for Obj-C)

New Question
Thank you for your reply Arcain. I guess question got mis-represented. I apologize for that.
My interpretation was like getFollowerIDsFor method as name suggests should be getting list of follower IDs, but it is not so.
My actual question is, how to use MGTwitterEngine API to get list of follower/following persons from Twitter. Though I went through documentation was not able to find out the same.
Regards,
Jennis
Previous Question
We can get list of Follower using getFollowerIDsFor through MGTwitterEngine object. It always returns some string which is not understandable for me i.e. how to decode or something like that ?
let say resultant string is "025815FA-BAF6-49E6-96B4-86F2D4C8C6CA"
how to understand what is there in this string ? can anyone highlight on this please ?
Help would be appreciated.
Regards,
Jennis
That value is a unique identifier and doesn't really mean anything. I'm not familiar with Cocoa, but when I looked around I found the following in the README file for MGTwitterEngine, and it seems relevant to what you're asking:
A note about the data returned from Twitter
Each Twitter API method returns an NSString which is a unique
identifier for that connection.
Those identifiers are passed to all
the delegate methods, so you can
keep track of what's happening.
Whenever a request is successful, you will receive a call to your
implementation of requestSucceeded: so
you'll know that everything went OK.
For most of the API methods, you will
then receive a call to the appropriate
method for the type of data you
requested (statusesReceived:... or
directMessagesReceived:... or
userInfoReceived:...). The values sent
to these methods are all NSArrays
containing an NSDictionary for each
status or user or direct message, with
sub-dictionaries if necessary (for
example, the timeline methods usually
return statuses, each of which has a
sub-dictionary giving information
about the user who posted that
status).
Just try calling some of the methods and use NSLog() to see what data you
get back; you should find the format
very easy to integrate into your
applications.
Sometimes, of course, requests will fail - that's just how life is. In the
unlikely event that the initial
connection for a request can't be
made, you will simply get nil back
instead of a connection identifier,
and then receive no further calls
relating to that request. If you get
nil back instead of an NSString, the
connection has failed entirely. That's
a good time to check that the computer
is connected to the internet, and so
on.
It's far more common however that the connection itself will go ahead just
fine, but there will be an error on
Twitter's side, either due to
technical difficulties, or because
there was something wrong with your
request (e.g. you entered the wrong
username and password, or you tried to
get info on a user that doesn't exist,
or some such thing). The specific
error conditions are mostly documented
in the Twitter API documentation
online.
In these cases you'll receive a call to requestFailed:withError: which will
include an NSError object detailing
the error. Twitter usually returns
meaningful HTTP error codes (like 404
for 'user not found', etc), and in
that case the -domain of the NSError
will be "HTTP" and the -code will be
the relevant HTTP status code. The
userInfo of the NSError will contain a
key "body" that may contain the
response body and "response" which
will contain the NSHTTPURLResponse.
This makes it really, really easy to
know what's happening with your
connections.

MVC 2.0 Post Form to action instead of redirect to action

I am using T4MVC to redirect to another action return RedirectToAction(MVC.MyController.MyAction());.
In result it is doing get request.
Is there any way to make post request from controller. I want to keep all the same but only make post instead get. I cant find any methods for that. I found one post helper here http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx but i cant pass any values i need using this post helper. I was trying to pass values through TempData but they are not coming when i using this helper. May be some one have any ideas?
The reason i want to do this because when user come from one controller to another and then if user click update or just click enter in browser address bar, page will break.
Should i use session for that reason?
A RedirectToAction will always perform a GET, never a POST (it returns a HTTP 302 to the browser, which will then issue a GET request).
To persist data across the redirect, if it is data that can be easily represented as a string and stored in the query string, then you can just add it to the route values of the redirect.
e.g.
return RedirectToAction("Search", new { searchString = "whatever" });
If it is a complex type, then you will need to store it in TempData. A number of other questions on StackOverflow (such as this one) give details on how.
If repeatedly storing to and reading from TempData across your application offends your code-sense, then you can encapsulate this by using the PassParametersDuringRedirect attribute and generic RedirectToAction available in the MvcContrib project. Some details on this technique are available here.
only way of doing post is by having a form and doing submit on that form, either with a submit button or with javascript, any info you want passed to that action must be in that form and you will find everything posted in FormCollection(hope I spelled it right).