发布数据时,IOS8 参数未附加到 URL
<p><p>我正在调用 REST 服务来发布 lat & lng,但是数据没有发送到服务器</p>
<pre><code>-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *crnLoc = ;
self.locationDesc.text = ;
NSLog(@"%@",crnLoc.description);
NSURL *aUrl = ;
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:aUrl];
NSString *params = [ initWithFormat:@"latitude=%g&longitude=%g", crnLoc.coordinate.latitude, crnLoc.coordinate.longitude];
;
];
[ initWithRequest:request delegate:self];
NSLog(@"%@",request.URL);
}
</code></pre>
<p><strong>我在上面的代码中做错了什么吗?</strong>我可以使用 REST Easy 客户端(firefox 插件)发布数据。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用此代码</p>
<pre><code>CLLocation *crnLoc = ;
self.locationDesc.text = ;
NSLog(@"%@",crnLoc.description);
NSURL *aUrl = ;
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:aUrl];
NSString *params = [ initWithFormat:@"latitude=%g&longitude=%g", crnLoc.coordinate.latitude, crnLoc.coordinate.longitude];
NSData *postData = ;
NSString *postLength = ];
;
;
;
;
NSURLConnection *con = [ initWithRequest:request delegate:self];
if(con)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
</code></pre>
<p>供引用:</p>
<p> <a href="https://stackoverflow.com/questions/15749486/sending-an-http-post-request-on-ios" rel="noreferrer noopener nofollow">Sending an HTTP POST request on iOS</a> </p></p>
<p style="font-size: 20px;">关于发布数据时,IOS8 参数未附加到 URL,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/30755081/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/30755081/
</a>
</p>
页:
[1]