Comments (5)
好吧,其实已经很简单了
把代码拖进去,在实际发请求之前,也可以在didFinishLaunch之后,开始写requestMock
from gyhttpmock.
同求、试了下、没起作用、不知道是不是用的不对、就是在request之前
mockRequest(@"GET", @"http://m.**.com/api/");
按理应该是把这个请求直接覆盖掉、但是还是收到了服务端的数据
from gyhttpmock.
这个应该不是完整的url,建议用示例中正则表达式的方式来匹配
from gyhttpmock.
mockRequest(@"GET", @"https://www.baidu.com")
.withBody(@"")
.andReturn(200)
.withBody(@"main_page.json");
NSURL *URL = [NSURL URLWithString:@"https://www.baidu.com"];
NSURLSessionDataTask *task = [self.session dataTaskWithURL:URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
}];
[task resume];
然后遇到下面这个错误。 我还不太会用,是不是写个可以运行的Demo啊!多谢!
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'response string is invaild json'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101ffed85 exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101a72deb objc_exception_throw + 48
2 CoreFoundation 0x0000000101ffebea +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001016bcd5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 URLSessionDemo 0x0000000101562012 __29-[GYMockResponseDSL withBody]_block_invoke + 1330
5 URLSessionDemo 0x000000010155d71d -[ViewController viewDidLoad] + 253
6 UIKit 0x000000010254f984 -[UIViewController loadViewIfRequired] + 1198
7 UIKit 0x000000010254fcd3 -[UIViewController view] + 27
8 UIKit 0x0000000102425fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
9 UIKit 0x000000010242669d -[UIWindow _setHidden:forced:] + 282
10 UIKit 0x0000000102438180 -[UIWindow makeKeyAndVisible] + 42
11 UIKit 0x00000001023aced9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
12 UIKit 0x00000001023b3568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
13 UIKit 0x00000001023b0714 -[UIApplication workspaceDidEndTransaction:] + 188
14 FrontBoardServices 0x0000000104e1d8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
15 FrontBoardServices 0x0000000104e1d741 -[FBSSerialQueue _performNext] + 178
16 FrontBoardServices 0x0000000104e1daca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
17 CoreFoundation 0x0000000101f24301 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
18 CoreFoundation 0x0000000101f1a22c __CFRunLoopDoSources0 + 556
19 CoreFoundation 0x0000000101f196e3 __CFRunLoopRun + 867
20 CoreFoundation 0x0000000101f190f8 CFRunLoopRunSpecific + 488
21 UIKit 0x00000001023aff21 -[UIApplication _run] + 402
22 UIKit 0x00000001023b4f09 UIApplicationMain + 171
23 URLSessionDemo 0x000000010155dd2f main + 111
24 libdyld.dylib 0x00000001047d892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
from gyhttpmock.
应该是这个main_page.json文件的json格式不对
from gyhttpmock.
Related Issues (16)
- 可以作为iOS的调试工具么 HOT 5
- 能模拟 Service 端 setCookie 吗? HOT 2
- podspec miss path of GYMockRequest.h cause can't find header warning HOT 1
- 示例crash了 HOT 1
- 期待交流 HOT 1
- Property 'regex' not found on object of type 'NSString *' HOT 1
- pod里面报找不到头文件 HOT 1
- 如果服务器返回的是一个数组,就没办法withbody拼接了啊 HOT 1
- 求解惑 HOT 4
- 可以加上日志功能 HOT 1
- 找不到JSON文件 HOT 3
- 可以Mock https请求吗? HOT 1
- 当请求返回的是一个 Array 时,Crash。
- Error: Error Domain=NSCocoaErrorDomain Code=2048 "The value “{"account" : "18621033332"}” is invalid." UserInfo={NSInvalidValue={"account" : "18621033332"}}'
- 没有办法拦截AFNetWorking的请求 需要额外的做操作吗
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gyhttpmock.