ASIFormDataRequest实现post的代码示例

用jquery实现的Post方法可能如下

var param = $.param({    data: JSON.stringify({"from":"234","messageid":"32132123","to":"234","conversationid":"4123456","timestamp":1459000790138,"type":1,"content":"ew","imageurl":""})});$http({    url: MAIN_HOST_URL + ‘/chat/createmessage‘,    method: "POST",    data: param,    headers: {‘Content-Type‘: ‘application/x-www-form-urlencoded‘}}).then(function (response) {    var data = response.data,        status = response.status,        header = response.header,        config = response.config;

    //console.log(JSON.stringify(data));

    if (status == 200) {

    }    $ionicLoading.show({template: data.m, noBackdrop: true, duration: 2000});

    scope.$broadcast(‘scroll.refreshComplete‘);}, function (response) {    //console.log("error: " + JSON.stringify(response));    var data = response.data,        status = response.status,        header = response.header,        config = response.config;

    //JSON.stringify(    scope.$broadcast(‘scroll.refreshComplete‘);});

相同的代码,可以转换到ios里,使用ASIFormDataRequest实现,代码如下:

.xx.h

@interface ChatViewController : UIViewController<ASIHTTPRequestDelegate> {

}

xx.m

- (void) postMessage {

NSString *s = [NSString stringWithFormat:@"http://%@/chat/createmessage", site_url];

ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:s]];

NSString *datas = @"{\"from\":\"234\",\"messageid\":\"32132123\",\"to\":\"234\",\"conversationid\":\"4123456\",\"timestamp\":1459000790138,\"type\":1,\"content\":\"ew\",\"imageurl\":\"\"}";

{

NSError *error;

//[request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded; encoding=utf-8"];

//[request addRequestHeader:@"Accept" value:@"application/json"];

//[request setRequestMethod:@"POST"];

//[request setPostBody:tempJsonData];

[request setPostValue:datas forKey:@"data"];

[request startAsynchronous];

}

}

- (void)requestFinished:(ASIHTTPRequest *)request

{

}

- (void)requestFailed:(ASIHTTPRequest *)request

{

NSError *error = [request error];

}

时间: 2024-07-29 05:52:17

ASIFormDataRequest实现post的代码示例的相关文章

计算DXFReader中多边形的面积代码示例

在DXFReader中, 一般的多边形的面积计算绝对值 其中K表是顶点的数目,它们的坐标,用于在求和和, 所以用下面的代码就可以计算出一个封闭的多段线的区域: view source print? 01 Dim Vertex As Object 02 Dim Entity As Object 03 Dim k As Long 04 Dim i As Long 05 Dim Area As Single 06 07 With DXFReader1 08 09  For Each Entity In

代码示例:一些简单技巧优化JavaScript编译器工作详解,让你写出高性能运行的更快JavaScript代码

告诉你一些简单的技巧来优化JavaScript编译器工作,从而让你的JavaScript代码运行的更快.尤其是在你游戏中发现帧率下降或是当垃圾回收器有大量的工作要完成的时候. 单一同态: 当你定义了一个两个参数的函数,编译器会接受你的定义,如果函数参数的类型.个数或者返回值的类型改变编译器的工作会变得艰难.通常情况下,单一同态的数据结构和个数相同的参数会让你的程序会更好的工作. function example(a, b) { // 期望a,b都为数值类型 console.log(++a * +

jquery操作单选钮代码示例

jquery操作单选钮代码示例:radio单选按钮是最重要的表单元素之一,下面介绍一下常用的几个jquery对radio单选按钮操作.一.取消选中: $(".theclass").each(function(){ if($(this).attr('checked')) { $(this).attr('checked',false); } }); 以上代码可以将class属性值为theclass的被选中单选按钮取消选中.二.获取被选中的单选按钮的值: var val=$('.thecla

Python实现各种排序算法的代码示例总结

Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示例总结,其实Python是非常好的算法入门学习时的配套高级语言,需要的朋友可以参考下 在Python实践中,我们往往遇到排序问题,比如在对搜索结果打分的排序(没有排序就没有Google等搜索引擎的存在),当然,这样的例子数不胜数.<数据结构>也会花大量篇幅讲解排序.之前一段时间,由于需要,我复习了

领域驱动开发推荐代码示例 — Microsoft NLayerApp

简介: Microsoft NLayerApp是由微软西班牙团队出品的基于.NET 4.0的“面向领域N层分布式架构”代码示例,在codeplex上的地址是:http://microsoftnlayerapp.codeplex.com/. 架构图: 点击查看大图 代码下载:http://microsoftnlayerapp.codeplex.com/releases/view/56660 所用到的软件: - Microsoft Visual Studio 2010  - Microsoft Ex

Aspectj快速上手代码示例之Before,After,Around

本文不打算解释AOP的相关专业名词和概念,仅通过几个代码示例来展示Aspectj(对AOP实现的)的基本使用,并且使用的Aspectj是目前最新版本. 1.搭建环境 本文使用Maven来构建工程,通过aspectj-maven-plugin插件来编译*.aj文件至.class. Maven的具体配置: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin&

jxl创建Excel文件java代码示例

记得要下载 并 导入 jxl.jar 包,免积分下载地址:http://download.csdn.net/detail/u010011052/7561041 package Test; import java.io.*; import jxl.*; import jxl.format.Colour; import jxl.write.*; public class JXLTest { private static WritableWorkbook book; private static Wr

java 翻盖hashCode()深入探讨 代码示例

package org.rui.collection2.hashcode; /** * 覆盖hashcode * 设计HashCode时最重要的因素 就是:无论何时,对同一个对象调用HashCode都应该产生同样的值, * 如果你的HashCode方法依赖于对象中易变的数据,用户就要当心了,因为此数据发生变化 时 * HashCode就会生成一个不同的散列码,相当于产生一个不同的健 * 此外 也不应该使HashCode依赖于具有唯一性的对象信息,尤其是使用this的值,这只能很糟糕, * 因为这

python 之初学者的代码示例(短小精悍)(一)

学习Python也有个把月了,最近整理自己初学的代码示例,一个是为了增加自己对细节的把握,一个是让像我一样的初学者能够熟练地使用基础,基础的重要性就不说了,我希望自己能够把这些精巧的小而短的示例分享给大家,共同进步 #help(execfile) Help on built-in function execfile in module __builtin__: execfile(...) execfile(filename[, globals[, locals]]) Read and execu