My question maybe unheard of or may even be impractical.
But, I believe it is practical and acceptable.
Problem: PHP request and response in background thread.
Problem constraints:
You know it uses POST method.
It has two fields fname and lname as html ids that need to be filled.
You get response in the same page i.e. index.php .
Pseudocode to solve the problem:
Open the website in background. Something like openURL("xyz(dot)com");
Read the data sent in html format.
Change the value of the fields fname and lname to required fields "Allen" and "Walker."
Now, submit the fields back to the server. ( Page has a submit button.)
Note: PHP code has a standard if-else check to check for those values. If the field is properly set, it then says "Success" else "Failed"
Again, get the response sent by the server.
Check if "Success" was returned.
If "success" was returned, UPDATE UI thread for saying "JOB done".
Else, "Job failed."
Note: I am not talking about using a WebView. Everything happens via a service or AsyncTask.
Now, this is a simple question, and any ideas or a direction is acceptable.
So, to recap. You have to open a webpage in background, change its field, submit it back and then get the response.
I know we can open a website and get its content. But, I would also like to know if what I said is possible or not. And, I know it is possible. And, that I only lack the knowledge on Java Web API, could you please guide me on this.
Thank You. And, Have a Good day!
use this link for best solution of calling web service without using WebView.
In this example fname and lname sent in namevaluepairs we get responce in json formet and parse json and get data also json parse defined in examples.
What you are trying to achieve is to create a webservice call using a AsyncTask.
Like you have mentioned, you can make a post request within the AsyncTask, passing in the variables required for the request.
You can find a good example as shown: Sending HTTP Post Request with Android
Related
I'm not sure if I'm understanding what slack means by a post request.
In my experience with what I'm familiar with it's either a curl request POST or with PHP use something like:
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
// get token
$token = $_POST['token'];
}
I'm not receiving anything from Slack though, Is it a cors problem? I tried that I enabled headers. I saw other questions, I can't seem to find much on this topic.
how to handle outgoing-webhook (Slack) using php
Slack outgoing webhook :URL(s)
I selected a channel, I also put in a trigger word, the return text is not related to the trigger word. Maybe by returning the text it's triggering/causing a loop? I just tried that no dice as well. There are no errors in apache, the code itself works, when I visit the link directly on my server it processes the code.
The incoming webhooks are no problem.
I don't understand I've tried this many times could never get it to work what am I missing?
Regarding the headers I wasn't sure what domain to match to, I didn't enable all (the star *) so I tried slack.com but it's possible that's not what slack uses to send out the request.
I am also learning on this, and there's not much documentation anywhere. I tried it yesterday. I sent a text with trigger words like "try send abcd". Based on the posted data to my public URL it will match the trigger word try with text "try send abcd". This text will be posted to the URL I provide in configuration and I catch the posted data like what's slack described in their docs with api response json raw body.
Anyway, the channel and url provided must be public and you need to provide a trigger words too. what's the posted data sent to your URL?
So far that's what I can do. I also plan to fetch them via js fetch(). if you've got any information on this kindly share it with me :)
I am a beginner and learning for example to submit a form to create an order (using POST method), edit an order (using PUT method), delete an order (using DELETE method) or search for an order (using GET method) targeting a restful web service. The order info is captured by the server script (probably PHP) and depending on the http method the order is either inserted, updated or deleted respectively. I have no knowledge of how the script does it.
My 2 questions are:
when I POST, PUT or DELETE, the server script could successfully perform the operation on the database (or) be unsuccessful in making changes to the database. How will I know if the script performed the database operation successfully or failed or there was some other error so that I can display a status to the user of the app accordingly?
(I understand that for a GET request the script sends the data requested in JSON or XML and I need to parse the JSON and display it to the app user. I just dont understand how it works for POST, PUT or DELETE. Will I receive a json for info or should I look somewhere else to able to provide a useful response to the app user).
I see POST being used instead of GET to get JSON response. My understanding is that POST is for insert operation only. Am I missing something? Why POST is being used in real time sometimes.
Thank you for your time in advance!
When the script finishes you send back a status code (200 is okay, 500-Internal server error, 404-Not found etc) and a message (json in your case)
"I see POST being used instead of GET to get JSON response", depends on what type of processing you are referring to. If you need a resource (a specific entity) you make a GET request, but if you need to make a custom process or a search then POST might be good for you
P.S: A good read on implementing a API an here. Check out the status codes used in the example, you can change your implementation based on your needs
I am having a very hard time understanding the exact process of "post/redirect/get".
I have combed through this site and the web for several hours and cannot find anything other than "here's the concept".
How to understand the post/redirect/get pattern?
Wikipedia explains this so well!
The Problem
The Solution
As you may know from your research, POST-redirect-GET looks like this:
The client gets a page with a form.
The form POSTs to the server.
The server performs the action, and then redirects to another page.
The client follows the redirect.
For example, say we have this structure of the website:
/posts (shows a list of posts and a link to "add post")
/<id> (view a particular post)
/create (if requested with the GET method, returns a form posting to itself; if it's a POST request, creates the post and redirects to the /<id> endpoint)
/posts itself isn't really relevant to this particular pattern, so I'll leave it out.
/posts/<id> might be implemented like this:
Find the post with that ID in the database.
Render a template with the content of that post.
/posts/create might be implemented like this:
If the request is a GET request:
Show an empty form with the target set to itself and the method set to POST.
If the request is a POST request:
Validate the fields.
If there are invalid fields, show the form again with errors indicated.
Otherwise, if all fields are valid:
Add the post to the database.
Redirect to /posts/<id> (where <id> is returned from the call to the database)
I'll try explaining it. Maybe the different perspective does the trick for you.
With PRG the browser ends up making two requests. The first request is a POST request and is typically used to modify data. The server responds with a Location header in the response and no HTML in the body. This causes the browser to be redirected to a new URL. The browser then makes a GET request to the new URL which responds with HTML content which the browser renders.
I'll try to explain why PRG should be used. The GET method is never supposed to modify data. When a user clicks a link the browser or proxy server may return a cached response and not send the request to the server; this means the data wasn't modified when you wanted it to be modified. Also, a POST request shouldn't be used to return data because if the user wants to just get a fresh copy of the data they're forced to re-execute the request which will make the server modify the data again. This is why the browser will give you that vague dialog asking you if you are sure you want to re-send the request and possibly modify data a second time or send an e-mail a second time.
PRG is a combination of POST and GET that uses each for what they are intended to be used for.
Just so people can see a code example (this is using express):
app.post('/data', function(req, res) {
data = req.body; //do stuff with data
res.redirect('public/db.html');
});
So to clarify, it instantly refreshes the webpage and so on refresh of that webpage (e.g. if you updated an element on it) it won't repost the form data.
My code used to look like this:
app.post('/data', function(req, res) {
data = req.body;
res.sendFile('public/db.html');
});
So here the response is sending the html file at the /data address. So in the address bar, after pressing the submit button it would say for me: localhost:8080/data.
But this means that on refresh of that page, if you have just submitted the form, it will submit it again. And you don't want the same form submitted twice in your database. So redirecting it to the webpage (res.redirect) instead of sending the file (res.sendFile) , stops the resubmission of that form.
It is all a matter of concept, there is no much more to understand :
POST is for the client to send data to the server
GET is for the client to request data from the server
So, conceptually, there is no sense for the server to answer with a resource data on a POST request, that's why there is a redirection to the (usually) same resource that has been created/updated. So, if POST is successful, the server opiniates that the client would want to fetch the fresh data, thus informing it to make a GET on it.
I've searched but can't find an answer.
There is a website with a contact form, the address end's like this: /?page_id=42, what I want is to send an email from this contact form through the iPhone, without entering the site, through PHP.
From the iPhone textfields.
so I did like this:
/?page_id=42contactname=hello&contactsubject=hey&contactemail=yositsa#gmail.com&contactmessage=this is just checking message
but I dont know why, it isn't sending me the message, what have I done wrong from the PHP and Objective-C side..
I dont have much knowledge in PHP and I'm new to Objective-C.
Thanks! :)
Like some other people have mentioned - does your PHP contact page use GET request variables? If unsure, check your contact page and look for $_POST. If you see this, just as a quick fix change all of your $_POST references to $_REQUESTS (which allow both POST and GET variables).
If this works, and you'd still like to use POST - then use something like ASIHTTPRequest in your iOS app to post the variables over.
URL you mentioned is like
`/?page_id=42contactname=hello&contactsubject=hey&contactemail=yositsa#gmail.com&contactmessage=this is just checking message`
I suspect here that you are missing & (ampersand) sign between page_id=42 and contactname. I am not sure this is the mistake but currently this is what I see from your current URL.
If this is not the problem try printing variables in which you fetch those parameters as all people have mentioned.
Or post your PHP and iOS side code so we can have a look in to that what is the exact problem.
Hope this helps.
The contact form probably works with POST variables. It's not a PHP thing, but an HTML thing. You need to send the variables in the body of an HTTP request, and you also need that request to be of type POST.
The query string you are trying to use means it's GET request, does your PHP form accept variables from the GET requests ?
Also make sure there are no hidden fields in the form that you might not be including.
I know it may be a bit late, but I just created a drop-in view controller to create an iOS "form" and post the variables to a web server. Not sure if the OP had access to the server side, but you can adapt this code to POST variables to existing web forms too.
It's on Github here:
https://github.com/mikecheckDev/MDContactForm
Let me know if you have any questions about it or need help and/or more features. It is still early in development but I found it useful in my project!
I need to generate RSS feed and get title and urls of the posts and so on. I decided to use Superfeedr for it. So in this situation, I'm a subscriber in Superfeedr. There is callback (the subscriber URL) field to get data, but I don't know what should be written in callback file. I researched the net for example code, but I found nothing about example code. BTW, I want to do this process in PHP. So if you know what should I need write to this file, please comment.
John, I think you got it... which is good. Now, what to write in your PHP: this callback url (your PHP file) will be called in 2 different cases:
to verify your intent (to confirm that you want to subscribe)
to notify you of new content.
I'm no PHP person, but I'll dscribe the algorithm for you
To differentiate between the two, you just have to look at the type of request. If it's a GET request, then, it's the verification of intent, and if it's a POST request, then it's the notification of new content.
If it's the verification of content, you just have to echo the hub.challenge provided as a GET param (I believe echo $_GET['hub.challenge']; should work). You should also verify that you really want to the subscription, but that the logic of your app and I don't know it (most people just look up the $_GET['hub.topic'] in their database and if it's there, echo the challenge. If not, echo something else.
If it's the notification of new content, it's a bit more complex. You have to access the BODY of the HTTP request (again, not sure how PHP does it, but I'm sure somebody can help), then, parse it to extract the title and urls, and handle them as you would want (most people will save that in their databases).
I hope this helps!
I'm using this code in php. Hope it helps someone
<?php
if(isset($_Get["hub_challenge"])){
echo $_Get["hub_challenge"];
return;
}