OC -网络请求 - NSURLConnection - POST
#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的更多相关文章
- OC -网络请求 - NSURLConnection - GET
#import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...
- iOS - OC - 网络请求 - 中文转码
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- iOS - NSURLConnection 网络请求
前言 @interface NSURLConnection : NSObject class NSURLConnection : NSObject DEPRECATED: The NSURLConne ...
- 多线程与网络之NSURLConnection发送请求
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- NSURLConnection 网络请求
前言 DEPRECATED: The NSURLConnection class should no longer be used. NSURLSession is the replacement f ...
- HTTP和GET/POST请求(NSURLConnection)
网络编程 网络编程是一种实时更新应用数据的常用手段 网络编程是开发优秀网络应用的前提和基础 网络基本概念 客户端(就是手机或者ipad等手持设备上面的APP) 服务器(远程服务器-本地服务器) 请求( ...
- iOS开发网络篇--NSURLConnection
S简介 NSURLConnection: 作用: 1.负责发送请求,建立客户端和服务器的连接发送数据给服务器 2.并收集来自服务器的响应数据 步骤: 1.创建一个NSURL对象,设置请求路径 2.传入 ...
- 网络&热恋NSURLConnection代理及GET¥POST请求
1.NSURLConnection代理下载设置在本地的身骑着白马MP3 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional ...
- iOS NSURLConnection和异步网络请求
在日常应用中,我们往往使用AFNetworking等第三方库来实现网络请求部分.这篇文章会简要地介绍一下如何使用NSURLConnection来进行异步的网络请求. 我们先看一个小demo - (vo ...
随机推荐
- 绕过限制,在PC上调试微信手机页面
场景 假设一个手机页面,开发者对其做了限制,导致只能在微信客户端中打开.而众所周知手机上非常不利于调试页面,所以需要能在电脑上打开并进行调试.这里针对常见的三种页面做一下分析,一一绕过其限制,(当然不 ...
- [UE4]编程师外挂Visual Assist X
Visual Assist X是一款非常好的Microsoft Visual Studio插件,可以支持Microsoft Visual Studio 2003,Microsoft Visual St ...
- Spark学习笔记4:数据读取与保存
Spark对很多种文件格式的读取和保存方式都很简单.Spark会根据文件扩展名选择对应的处理方式. Spark支持的一些常见文件格式如下: 文本文件 使用文件路径作为参数调用SparkContext中 ...
- java编译器知识
代码编译器: 代码: 编译就是讲一种代码编译成计算机可以理解的指令. ================================================================= ...
- linux优化之全过程
基于开放源代码的Linux给用户提供了这样一个平台:可以根据自己的软.硬件环境,定制自己的Linux应用环境.因此,根据每个用户不同的应用范围定制应用环境,可以将Linux系统的性能提升到新的高度. ...
- HTML5进阶
内容: 1.geolocation元素 2.video元素和audio元素 3.localStorage 4.WebWorker 5.WebSQL.IndexedDB 6.文件操作.文件拖拽新概念 7 ...
- python数据结构之链表(一)
数据结构是计算机科学必须掌握的一门学问,之前很多的教材都是用C语言实现链表,因为c有指针,可以很方便的控制内存,很方便就实现链表,其他的语言,则没那么方便,有很多都是用模拟链表,不过这次,我不是用模拟 ...
- python 编码文件json.loads json.dumps
import yaml d = {'name': '张三', 'age': '1'} print d jd = json.dumps(d, ensure_ascii=False, encoding=' ...
- OpenACC 异步计算
▶ 按照书上的例子,使用 async 导语实现主机与设备端的异步计算 ● 代码,非异步的代码只要将其中的 async 以及第 29 行删除即可 #include <stdio.h> #in ...
- 红帽yum源安装报错initscripts-9.49.41-1.el7.x86_64 conflicts redhat-release < 7.5-0.11" ?
https://access.redhat.com/solutions/3425111 环境 Red Hat Enterprise Linux 7 问题 yum fails to apply upda ...