android 客户端restful,android restful

Android RESTFUL请求:

删除 DEL:

//创建一个http客户端

HttpClientclient=newDefaultHttpClient();

//创建一个DELETE请求

HttpDeletehttpDelete=newHttpDelete("http://www.store.com/product/1234");

//向服务器发送DELETE请求并获取服务器返回的结果,可能是删除成功,或者失败等信息

HttpResponseresponse=client.execute(httpDelete);

修改 PUT:

//创建一个http客户端

HttpClientclient=newDefaultHttpClient();

//创建一个PUT请求

HttpPuthttpPut=newHttpPut("http://www.store.com/product/1234");

//组装数据放到HttpEntity中发送到服务器

final ListdataList=newArrayList();

dataList.add(new BasicNameValuePair("price", "11.99"));

HttpEntityentity=newUrlEncodedFormEntity(dataList, "UTF-8");

httpPut.setEntity(entity);

//向服务器发送PUT请求并获取服务器返回的结果,可能是修改成功,或者失败等信息

HttpResponseresponse=client.execute(httpPut);

获取数据GET:

//创建一个http客户端

HttpClientclient=newDefaultHttpClient();

//创建一个GET请求

HttpGethttpGet=newHttpGet("http://www.store.com/products");

//向服务器发送请求并获取服务器返回的结果

HttpResponseresponse=client.execute(httpGet);

//返回的结果可能放到InputStream,http Header中等。

InputStreaminputStream=response.getEntity().getContent();

Header[]headers=response.getAllHeaders();

新增数据 POST:

//创建一个http客户端

HttpClientclient=newDefaultHttpClient();

//创建一个POST请求

HttpPosthttpPost=newHttpPost("http://www.store.com/product");

//组装数据放到HttpEntity中发送到服务器

final ListdataList=newArrayList();

dataList.add(new BasicNameValuePair("productName", "cat"));

dataList.add(new BasicNameValuePair("price", "14.87"));

HttpEntityentity=newUrlEncodedFormEntity(dataList, "UTF-8");

httpPost.setEntity(entity);

//向服务器发送POST请求并获取服务器返回的结果,可能是增加成功返回商品ID,或者失败等信息

HttpResponseresponse=client.execute(httpPost);

IOS RESTFUL:

SVHTTPRequest 获取数据:

[[SVHTTPClient sharedClient] setBasePath:@"http://api.twitter.com/1/"];          [[SVHTTPClient sharedClient] GET:@"users/profile_image"                           parameters:[NSDictionary dictionaryWithObjectsAndKeys:                                       @"samvermette", @"screen_name",                                       @"original", @"size",                                       nil]                           completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {                               imageCell.image = [[NSImage alloc] initWithData:response];                            }];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值