我創建了一個Web服務來在iOS應用程序和Joomla網站之間進行通信,並且我使用GET方法在移動應用程序和Web服務之間進行通信, web服務和控制器(做文件並返回數據的PHP文件),但我沒有找到如何將實現轉換爲POST方法,這裏是實際系統:將Web服務從GET轉換爲POST
ws.php:它是web服務(簡單示例)
<?php
$id = $_GET['id'] ; // get the data from the URL
// here i make testes
// then I redirect to the controller of the Joomla component that receive
// the call of the request the URL is actually the attribute "action" of
// an existing HTML Form that implement the login system, I added a
// parameter called web service to help me to modify the controller
// to make the difference between a normal call and a web service call
header("Location: index.php?option=com_comprofiler&task=login&ws=1&id=1");
?>
Controller.php這樣:Web服務調用的接收器和網絡電話(從瀏覽器)
<?php
// code added by me, in the existent controller of the component
// it was waiting for a form submitting, so I got to convert my data to POST here
if (isset($_GET['ws'])) // it's a web service call
{
$_POST['id'] = $_GET['id'] ;
// do the task ...
if ($correctLogin) // just an example
echo "1"
else
echo '0';
}
?>
我沒有把真正的實現,這是該系統的只是一個簡單的例子,但它是相同的從移動
NSURL *url = [[NSURL alloc]initWithString:@"http://localhost/ws.php?id=1"];
NSData *dataUrl= [NSData dataWithContentsOfURL:url];
NSString *str = [[NSString alloc]initWithData:dataUrl
encoding:NSUTF8StringEncoding];
if(![str isEqualToString:@"0"])
NSLog(@"connected");
else
NSLog(@"not connected");
所以
呼叫我不想使用GET方法,我只是想從使用POST手機收到我的數據,並使用這些數據發送到控制器POST也什麼是最好的解決方案?
你就不能使用'$ _REQUEST',因爲它可以同時處理'$ _POST'和'$ _GET'? – j08691 2013-02-09 20:31:18
我不想在開始時使用'$ _GET',我只是想使用'$ _POST'從移動設備發送數據,並且從web服務發送數據給控制器。在實際系統中,我使用重定向從兩個PHP文件發送數據,但是我想更改它並使用'$ _POST'在兩個PHP文件之間以及移動應用程序和Web服務之間發送數據。 – Aladin 2013-02-09 20:38:49