Skip to content

python3.7 flask2.2.3 webapi can be connected by Postman and browser but not c# Net6 HttpClient.PostAsync #5089

@superdavid0816

Description

@superdavid0816

Hi,
I build a very simple web api by flask2.2.3 using python3.7.
I can use Postman and browser to connect this webapi but not working in c# Net6 by HttpClient.PostAsync.
Please help me to pass this error.
Thank you.

error message in c#:


{System.Net.Sockets.SocketException (111): Connection refused
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)}


here is the code:


from flask import Flask, jsonify, redirect, url_for, render_template,request, Response
import json
from flask_cors import CORS

app = Flask(name)
CORS(app)

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

return jsonify(True);

if name == 'main':
app.run(host='0.0.0.0',port=58080,debug=True)


Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions