1

Hi there I am trying to integrate an api with flutter but a strange merged. Have an idea?

It shows link includes some '%' figure but especially it does not. Where is the problem. It is a basic think to post a request an api.

void yap ()async
  {
    //https://www.payfast.co.za/eng/process
    //https://sandbox.payfast.co.za​/eng/process


    String url3 = "https://sandbox.payfast.co.za​/eng/process";
    //String pkistring = v1hashing(requeststr);
    HttpClient httpClient = new HttpClient();
    HttpClientRequest request = await httpClient.postUrl(Uri.parse(url3));

    //headers
    //request.headers.set('Accept' ,  'application/json');
        Map body = { "merchant_id" :"10000100",
                    "merchant_key" :"46f0cd694581a",
                      "amount" :"100.00",
                          "item_name" :"Test Product"} ;
    
    //body
        request.add(utf8.encode(json.encode(body)));
    
    //response cevap
        HttpClientResponse response = await request.close();
        print(response.statusCode); // baglanti yapildi mi yapilmadi mi 200 ise yapildi
        String reply = await response.transform(utf8.decoder).join();
        //Map responseMap = json.decode(reply);
        httpClient.close();
        print("payfast ici odeme");
        print(reply);
    
      }

Error Text;

 Unhandled Exception: FormatException: sandbox.payfast.co%E2%80%8B is not a valid link-local address but contains %. Scope id should be used as part of link-local address. (at character 19)
sandbox.payfast.co%E2%80%8B
                  ^
15
  • How about changing Uri.parse(url3) into Uri.parse(url3.trim()). Commented May 29, 2021 at 22:14
  • remains the same unfortunately Commented May 29, 2021 at 22:35
  • Try adding 'r' to avoid special characters: String url3 = r"sandbox.payfast.co.za​/eng/process"; Commented May 29, 2021 at 22:41
  • How about changing Uri.parse(url3) into Uri.parse(Uri.decodeFull(url)) Commented May 29, 2021 at 22:52
  • 1
    Yep. That you can define uri in different variavle for cleab code sake. Commented May 29, 2021 at 23:03

1 Answer 1

2

Use Uri.https instead of Uri.parse.

In case if url is http use Uri.http.

But the structure of both methods are same. Docs for Uri.http: https://api.dart.dev/stable/2.10.5/dart-core/Uri/Uri.http.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.