如何调用API POST方法 [英] How to call API POST Method

查看:72
本文介绍了如何调用API POST方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已开发API应用程序将其用于另一个应用程序,我有一个Action接收图像作为Base64并将其保存在硬盘上。



这是此函数的realIP链接 - http://84.235.50.145:9111/api/jobs/ImageSender [ ^ ]



这是我开发的API方法

I have Developed API Application to use it for Another application and i have an Action to receive image as Base64 and save it on the hard disk.

Here is the link of the realIP of this function - http://84.235.50.145:9111/api/jobs/ImageSender[^]

Here is The API Method i developed

[HttpPost]
[ActionName("ImageSender")]
public void ImgSender(string value)
{
    var base64 = value;

    string ImgPath = LoadImage(base64);
}

public string LoadImage(string img)
{
    byte[] bytes = Convert.FromBase64String(img.Replace(' ', '+'));

    Random Ran = new Random();
    string AddToName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + Ran.Next(199999);

    try
    {
        System.IO.File.WriteAllBytes(@"F:\EmploymentFiles\img" + AddToName + ".jpg", bytes);

        return @"EmploymentFiles/img" + AddToName + ".jpg";
    }
    catch (Exception ee)

    { return ee.ToString(); }

}



我想从aspx页面调用此函数并上传图像。



如何在aspx中执行此操作?







已添加标签。

[/编辑]

推荐答案

有几种方法,但也许最容易利用正在使用jQuery库的ajax方法...

http://api.jquery.com/jquery。 ajax / [ ^ ]

代码应如下所示:

There are several way, but maybe the most easy to utilize is using jQuery library ajax methods...
http://api.jquery.com/jquery.ajax/[^]
The code should look like this:


.ajax({
method: POST
url: http://84.235.50.145:9111/api/jobs/ImageSender,
数据:base64string,
dataType: text
});
.ajax({ method: "POST", url: "http://84.235.50.145:9111/api/jobs/ImageSender", data: base64string, dataType: "text" });


这篇关于如何调用API POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆