如何从Acumatica内部发出外部HTTP请求

如何从Acumatica内部发出外部HTTP请求,acumatica,Acumatica,我想从输入销售订单屏幕(SO301000)上的自定义操作发出GET请求。我们有一个单独的系统,用于向客户发送确认电子邮件。客户服务将使用该操作手动触发电子邮件 我尝试过使用HttpClient类,但它告诉我“找不到类型或命名空间名称‘HttpClient’(是否缺少using指令或程序集引用?)。我正在引用System.Net、System.Net.Http和System.Net.Http.Headers命名空间,因此我想知道System.Net.Http程序集是否未被Acumatica引用 是

我想从输入销售订单屏幕(SO301000)上的自定义操作发出GET请求。我们有一个单独的系统,用于向客户发送确认电子邮件。客户服务将使用该操作手动触发电子邮件

我尝试过使用HttpClient类,但它告诉我“找不到类型或命名空间名称‘HttpClient’(是否缺少using指令或程序集引用?)。我正在引用System.Net、System.Net.Http和System.Net.Http.Headers命名空间,因此我想知道System.Net.Http程序集是否未被Acumatica引用


是否有更好的方式发出外部请求?

不幸的是,Acumatica没有引用System.Net.Http程序集。也就是说,不可能在放置到定制中的C代码文件中使用HttpClient


不过,另一种选择是创建一个扩展库,该库将引用System.Net.Http程序集,并将dll包含到定制中,而不是C代码文件中。有关扩展库的更多信息,请检查

以扩展RuslanDev的建议,以下是该扩展库的代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace MyApp
{
    public static class Utility
    {
        private static WebRequest CreateRequest(string url, Dictionary headers)
        {
            if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                WebRequest req = WebRequest.Create(url);
                if (headers != null)
                {
                    foreach (var header in headers)
                    {
                        if (!WebHeaderCollection.IsRestricted(header.Key))
                        {
                            req.Headers.Add(header.Key, header.Value);
                        }
                    }
                }
                return req;
            }
            else
            {
                throw(new ArgumentException("Invalid URL provided.", "url"));
            }
        }
        public static string MakeRequest(string url, Dictionary headers = null)
        {
            WebResponse resp = CreateRequest(url, headers).GetResponse();
            StreamReader reader = new StreamReader(resp.GetResponseStream());
            string response = reader.ReadToEnd();
            reader.Close();
            resp.Close();
            return response;
        }
        public static byte[] MakeRequestInBytes(string url, Dictionary headers = null)
        {
            byte[] rb = null;
            WebResponse resp = CreateRequest(url, headers).GetResponse();
            using (BinaryReader br = new BinaryReader(resp.GetResponseStream()))
            {
                rb = br.ReadBytes((int)resp.ContentLength);
                br.Close();
            }
            resp.Close();
            return rb;
        }
    }
}