设置正确的url路径不起作用,目标C

2024-09-27 23:26:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用此代码在Objective C中发出post请求

NSURL *baseURL = [NSURL URLWithString:@"http://192.168.1.147:5000/test"];


    //static NSString *test = @"http://192.168.1.147:5000/test";
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *topView = window.rootViewController.view;



    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];

    [manager POST:@"/" parameters:eventInfoObject success:^(NSURLSessionDataTask *task, id responseObject) {
    ....

我在Python中有两个使用Flask的函数:

@app.route("/", methods=['GET'])
def hello():

@app.route("/test", methods=['POST'])
def addEvent():

使用Charles查看发生了什么这是尝试使用Objective-C中的代码时得到的结果:

enter image description here

正如您所看到的,URL is not/test还表示405 METHOD not ALLOWED,这意味着它是Python中第一个只允许GET请求的方法。为什么不直接指向addEvent()函数?你知道吗


Tags: 函数代码testapphttpmanagerwindowpost

热门问题