GithubHelp home page GithubHelp logo

Comments (5)

hypoyao avatar hypoyao commented on June 16, 2024

好吧,其实已经很简单了
把代码拖进去,在实际发请求之前,也可以在didFinishLaunch之后,开始写requestMock

from gyhttpmock.

njafei avatar njafei commented on June 16, 2024

同求、试了下、没起作用、不知道是不是用的不对、就是在request之前
mockRequest(@"GET", @"http://m.**.com/api/");
按理应该是把这个请求直接覆盖掉、但是还是收到了服务端的数据

from gyhttpmock.

hypoyao avatar hypoyao commented on June 16, 2024

这个应该不是完整的url,建议用示例中正则表达式的方式来匹配

from gyhttpmock.

lanjing99 avatar lanjing99 commented on June 16, 2024

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.

hypoyao avatar hypoyao commented on June 16, 2024

应该是这个main_page.json文件的json格式不对

from gyhttpmock.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.