zoukankan      html  css  js  c++  java
  • 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];

    }

  • 相关阅读:
    pg-xl 基于 pgxc_ctl 安装与使用
    pg-xl 的基本方式添加节点
    pg-xl 的基本方式安装与使用
    oracle 12.2.0.1 + oracle goldengate 12.3.0.1.4 之一 dml
    postgresql 高可用 etcd + patroni 之二 patroni
    postgresql 高可用 etcd + patroni 之一 etcd
    rvm,ruby的安装
    oracle 12.2.0.1 使用 active dataguard broker 之二 failover
    oracle 12.2.0.1 使用 active dataguard broker 之二 switchover
    es 6.3 .tar.gz 安装
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/5332347.html
Copyright © 2011-2022 走看看