POSTing data while redirecting to a third-party URL using Response.Redirect()

POSTing data while redirecting to a third-party URL using Response.Redirect()



In ASP.Net Core 2.0, how can I POST data while redirecting to a third-party URL using Response.Redirect()?


Response.Redirect()



Note: I have to POST this data without using the query-string.






I have to redirect the url with data to third party payment gateway. So how can I achieve this using Response.Redirect() method in ASP.Net Core 2.0? or else if you have anyother ideas please suggest me.

– Alexandar Rajavel
Sep 11 '18 at 11:05






For example my third party pamentgateway url is: xxxx:xxxx/PaymentGatewayWrapper.aspx var requestData="some data"; Dictionary<string, object> postData = new Dictionary<string, object>(); postData.Add("requestToJson", requestData); Finaly I have to redirect to above url with this postData

– Alexandar Rajavel
Sep 11 '18 at 11:12




3 Answers
3



Response.Redirect triggers a GET request which means that the only option is using a query string.
Can you trigger the redirection from the client (if any) in order to make a POST request?






I have to redirect the url with data to third party payment gateway. So how can I achieve this using Response.Redirect() method in ASP.Net Core 2.0? or else if you have anyother ideas please suggest me.

– Alexandar Rajavel
Sep 11 '18 at 11:03






Take a look at this answer stackoverflow.com/questions/4015324/…

– A. Roussos
Sep 14 '18 at 7:52



You must use object if you want post data without using query string.


[HttpPost]
public IActionResult Search([FromBody] CustomerSearchRequestApiModel request)

if (request == null)

return BadRequest();


return Ok(request);






I have to redirect the url with data to third party payment gateway. So how can I achieve this using Response.Redirect() method in ASP.Net Core 2.0? or else if you have anyother ideas please suggest me.

– Alexandar Rajavel
Sep 11 '18 at 11:02



It is impossible to use Response.Redirect() to send Post request.


Response.Redirect()


Post



For a workaround, you could try HttpClient to send Post request and then return the reponse to the web browser with ContentResult as text/html.


HttpClient


Post


ContentResult


text/html



Here is a demo code:


public async Task<ContentResult> HtmlView()

using (var formDataContent = new MultipartFormDataContent())

HttpClient client = new HttpClient();
Article article = new Article ArticleName = "AN" ;

formDataContent.Add(new StringContent("AN", Encoding.UTF8, "application/json"), "ArticleName");
using (HttpClient httpClient = new HttpClient())

HttpResponseMessage response = await httpClient.PostAsync(@"https://localhost:44393/Articles/Create", formDataContent);
return new ContentResult

ContentType = "text/html",
StatusCode = (int)response.StatusCode,
Content = await response.Content.ReadAsStringAsync()
;






Note



Change the HttpClient part to send the right request to your own third party url with validate parameters.


HttpClient






Hi Tao Zho, thanks for your reply but the Requirement is: POSTing data while redirecting to a third-party payment gateway URL using Response.Redirect() then that third-party URL will be open a web page in that page user has to enter theire credentials for payment purpose.

– Alexandar Rajavel
Sep 12 '18 at 9:10



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ