#import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self post];
} -(void)post
{
//1.确定请求路径
NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login"]; //2.创建可变请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; //3.修改请求方法,POST必须大写
request.HTTPMethod = @"POST"; //设置属性,请求超时
request.timeoutInterval = ; //设置请求头User-Agent
//注意:key一定要一致(用于传递数据给后台)
[request setValue:@"ios 10.1" forHTTPHeaderField:@"User-Agent"]; //4.设置请求体信息,字符串--->NSData
request.HTTPBody = [@"username=520it&pwd=123&type=JSON" dataUsingEncoding:NSUTF8StringEncoding]; //5.发送请求
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { //6.解析数据,NSData --->NSString
NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
}];
} @end

OC -网络请求 - NSURLConnection - POST的更多相关文章

  1. OC -网络请求 - NSURLConnection - GET

    #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...

  2. iOS - OC - 网络请求 - 中文转码

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  3. iOS - NSURLConnection 网络请求

    前言 @interface NSURLConnection : NSObject class NSURLConnection : NSObject DEPRECATED: The NSURLConne ...

  4. 多线程与网络之NSURLConnection发送请求

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  5. NSURLConnection 网络请求

    前言 DEPRECATED: The NSURLConnection class should no longer be used. NSURLSession is the replacement f ...

  6. HTTP和GET/POST请求(NSURLConnection)

    网络编程 网络编程是一种实时更新应用数据的常用手段 网络编程是开发优秀网络应用的前提和基础 网络基本概念 客户端(就是手机或者ipad等手持设备上面的APP) 服务器(远程服务器-本地服务器) 请求( ...

  7. iOS开发网络篇--NSURLConnection

    S简介 NSURLConnection: 作用: 1.负责发送请求,建立客户端和服务器的连接发送数据给服务器 2.并收集来自服务器的响应数据 步骤: 1.创建一个NSURL对象,设置请求路径 2.传入 ...

  8. 网络&热恋NSURLConnection代理及GET¥POST请求

    1.NSURLConnection代理下载设置在本地的身骑着白马MP3 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional ...

  9. iOS NSURLConnection和异步网络请求

    在日常应用中,我们往往使用AFNetworking等第三方库来实现网络请求部分.这篇文章会简要地介绍一下如何使用NSURLConnection来进行异步的网络请求. 我们先看一个小demo - (vo ...

随机推荐

  1. Windows7无法访问共享文件夹(0x800704cf,0x80070035)解决方法

    Windows7系统突然无法访问Linux的samba服务器,出现0x800704cf或者0x80070035错误,也不能访问其他windows机器的共享文件夹,解决方案如下两张图,配置与下面两张图为 ...

  2. jQuery动态的给页面中添加一条样式表的链接

    HTML部分: <input type="button" value="单击" onclick="getbody()" /> & ...

  3. xgCalendar在ASP.NET中的使用

    1.将wdCalendar文件夹考入项目中 2.在页面中添加引用,见3中head标签中定义 3.配置xgCalendar,两段代码放在一起就是完整的页面 body> <div> &l ...

  4. 第3章 文件I/O(4)_dup、dup2、fcntl和ioctl函数

    5. 其它I/O系统调用 (1)dup和dup2函数 头文件 #include<unistd.h> 函数 int dup(int oldfd); int dup2(int oldfd, i ...

  5. 长沙雅礼中学集训-------------------day1(内含day0)

    day0: 首先,请允许我吐槽一下: 1.那些一个人住一个标准房的人您们真的是#@**¥&%……#*()%……*()@Q$&. 2.感谢那些一个人住一个标准间的人,要不然我们也找不到这 ...

  6. java的多态性(二)

    2013-10-16 19:44 9364人阅读 评论(25) 收藏 举报  分类: [JAVA开发]-----Java提高篇(36)  版权声明:本文为博主原创文章,未经博主允许不得转载.   目录 ...

  7. python3 string

    字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello World!' var2 ...

  8. X-Requested-With

    最近工作中发现,使用angular $http跨域的时候,虽然后台已经配置了跨域允许,但是还是报错. 查资料发现,angular $http 的request的请求头中,默认有: Access-Con ...

  9. HTML5中常用的标签(及标签的属性和作用)

    1.标签:<!DOCTYPE>作用:声明是文档中的第一成分,位于<html>标签之前. 2.标签:<html>作用:此元素可告知浏览器其自身是一个HTML文档.属性 ...

  10. 0_Simple__simpleStreams

    对比使用单流和多流(4条)情况下数据拷贝,以及数据拷贝加内核调用的效率差别.▶ 源代码 #include <stdio.h> #include <cuda_runtime.h> ...