.net - 使用 .net 通过 HTTPS 将 xml 发布到 Paypal Reporting API 时出错

标签 .net xml paypal xmlhttprequest

您好,我正在尝试使用 .Net 通过 HTTPS 将以下 xml 发布到 PayPal 报告引擎。我正在尝试使用 .net 以编程方式生成 payPal 报告。我检查了 PayPal 报告 API 的文档并创建了下面的 xml 文件。我想将此 XML 发布到 paypal 以生成报告。请求的内容/类型应该是文本/纯文本。但是我收到异常抛出消息我正在 try catch 异常但无法做到这一点。如果我更改程序,我不会收到任何响应,并且根据 PayPal 文档,响应将是包含状态代码的 xml 文件。

每日事件.xml

<?xml version="1.0" encoding="UTF-8"?>
<reportingEngineRequest>
<authRequest>

<vendor>**</vendor>
<partner>**</partner>
<password>**</password>
</authRequest>
<runReportRequest>
<reportName>DailyActivityReport</reportName>
<reportParam>
<paramName>report_date</paramName>
<paramValue>2007-10-10</paramValue>
</reportParam>
<pageSize>50</pageSize>
</runReportRequest>
</reportingEngineRequest>

我的C#代码如下

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
   using System.Net.Http;
  using System.Net.HttpWebRequest;

  namespace RunPaypalReport
  {
   class Program
   {
     static void Main(string[] args)
    {
        string URL = "https://payments-reports.paypal.com/test-reportingengine";
        string filename = "report.xml";
        try
        {
            WebRequest request = WebRequest.Create(URL);

            //Set values for the request back
            request.Method = "POST";
            request.ContentType = "text/plain";
            string postdata = GetTextFromXMLFile(filename);
            Console.Write(postdata);
            //   byte[] byteArray = Encoding.Default.GetBytes(postdata);
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postdata);
            request.ContentLength = bytes.Length;

            using (Stream os = request.GetRequestStream())
            {
                os.Write(bytes, 0, bytes.Length);
            }

            using (System.Net.WebResponse response = request.GetResponse())
            {
                if (response == null)
                    return;

                    using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
                    {
                        string post = sr.ReadToEnd().Trim();

                        Console.Write(post);
                        sr.Close();
                        return;
                    }

            }
        }

        catch (Exception e)
        {
            Console.Write(e.Message);
        }
    }

    private static string GetTextFromXMLFile(string file)
    {
      StreamReader reader = new StreamReader(file);
      string ret = reader.ReadToEnd();
      reader.Close();
    // Console.Write(ret);
      return ret;
    }       }
  }

最佳答案

终于收到回复了。错误在 XML 文件中。我们需要在请求 xml 中添加用户,用户应该是您的商家登录。通过添加用户,我收到了一个 xml 响应。 下面是更新的 XML

  <?xml version="1.0" encoding="utf-8" ?>
  <reportingEngineRequest>
  <authRequest>
  <user>Vendor/MerchantID</user>
  <vendor>Vendor/MerchantID</vendor>
  <partner>********</partner>
  <password>*******</password>
  </authRequest>
  <runReportRequest>
  <reportName>DailyActivityReport</reportName>
  <reportParam><paramName>report_date</paramName>
  <paramValue>2014-10-02</paramValue>
  </reportParam>
  <pageSize>50</pageSize>
  </runReportRequest>
  </reportingEngineRequest>

关于.net - 使用 .net 通过 HTTPS 将 xml 发布到 Paypal Reporting API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26169002/

相关文章:

mysql - 当使用 32 位版本的 MySQL 的 .net 连接器连接到 64 位版本的 MySQL 时,我得到 "Waiting for table metadata lock "

android - 从android中的任务管理器堆栈中删除 Activity

asp.net - 如何在 Simile Timeline 中重新加载数据

c# - 处理 TypedDataset 中的 Null

c# - 单例和 HttpApplicationState

PayPal IPN 无法在沙箱中工作

asp.net - 从 Paypal 网站返回后,使用 Paypal 付款不起作用

android - paypal android sdk 货币错误错误

c# - 如何在 C# 中获取目录大小(目录中的文件)?

java - 发送 SOAP 请求以使用您自己的服务