send a Post HTTPRequest to a Identity Check company

天涯浪子 提交于 2020-07-08 00:42:11

问题


I am trying to send a Post HTTPRequest to a Identity check company. I created JSON file and tested the file using SOAPUI and I got the response back using SOAP UI. I tried to send the same JSON file using my code below:

public void test()
    {
        string Hmackey = "XXXXX";
try
        {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("https://test");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
                client.DefaultRequestHeaders.TryAddWithoutValidation("hmac-signature", Hmackey);
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "relativeAddress");
                request.Content = new StringContent(JSONstring,
                                                    Encoding.UTF8,
                                                    "application/json");//CONTENT-TYPE header
                                                                        // var response = client.SendAsync(request).Result;

                var response = client.SendAsync(request).GetAwaiter().GetResult();

            }

I got the following response back. Below is from immediate window:

{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  X-OneAgent-JS-Injection: true
  Cache-Control: no-store, must-revalidate, no-cache
  Set-Cookie: dtCookie=3$XX0FF82C29851C2F5CE671F083497XXD; Path=/; Domain=.test.com
  Content-Length: 1282
  Content-Type: text/html; charset=ISO-8859-1
}}
    Content: {System.Net.Http.StreamContent}
    Headers: {X-OneAgent-JS-Injection: true
Cache-Control: no-store, must-revalidate, no-cache
Set-Cookie: dtCookie=3$XX0FF82C29851C2F5CE671F083497XXD; Path=/; Domain=.test.com
}
    IsSuccessStatusCode: false
    ReasonPhrase: "Not Found"
    RequestMessage: {Method: POST, RequestUri: 'https://test', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Accept: application/json
  hmac-signature: XXXXX
  Content-Type: application/json; charset=utf-8
  Content-Length: 3176
}}
    StatusCode: NotFound
    Version: {1.1}

Below is my JSON file. IN C#, it has lot of "/r/n" and "/". I cleaned up the JSON file for clarity, but when I am sending my JSOn file to the client, it has all "/r/n" and "/"

{
    "header": {
        "tenantId": "213213",
        "requestType": "PreciseIdOnly",
        "clientReferenceId": "213213",
        "expRequestId": "",
        "txnId": "",
        "messageTime": "2020-06-08T11:38:02Z",
        "options": {}
    },
    "payload": {
        "control": [
            {
                "option": "PIDXML_VERSION",
                "value": "06.00"
            },
            {
                "option": "SUBSCRIBER_PREAMBLE",
                "value": "3333"
            },
            {
                "option": "SUBSCRIBER_OPERATOR_INITIAL",
                "value": "dd"
            },
            {
                "option": "SUBSCRIBER_SUB_CODE",
                "value": "234124"
            },
            {
                "option": "PID_USERNAME",
                "value": "demo"
            },
            {
                "option": "PID_PASSWORD",
                "value": "xxxx"
            },
            {
                "option": "VERBOSE",
                "value": "Y"
            },
            {
                "option": "PRODUCT_OPTION",
                "value": "11"
            },
            {
                "option": "DETAIL_REQUEST",
                "value": "D"
            },
            {
                "option": "VENDOR",
                "value": "111"
            },
            {
                "option": "VENDOR_VERSION",
                "value": "11"
            },
            {
                "option": "BROKER_NUMBER",
                "value": ""
            },
            {
                "option": "END_USER",
                "value": ""
            },
            {
                "option": "FREEZE_KEY_PIN",
                "value": ""
            }
        ],
        "contacts": [
            {
                "id": "APPLICANT_CONTACT_ID_1",
                "person": {
                    "typeOfPerson": "",
                    "personIdentifier": "",
                    "personDetails": {
                        "dateOfBirth": "",
                        "yearOfBirth": "",
                        "age": "",
                        "gender": "",
                        "noOfDependents": "",
                        "occupancyStatus": "",
                        "mothersMaidenName": "",
                        "spouseName": ""
                    },
                    "names": [
                        {
                            "id": "",
                            "firstName": "Test",
                            "middleNames": "D",
                            "surName": "TEST",
                            "nameSuffix": ""
                        }
                    ]
                },
                "addresses": [
                    {
                        "id": "Main_Contact_Address_0",
                        "addressType": "CURRENT",
                        "poBoxNumber": "",
                        "street": "34214 TEST DRIVE",
                        "street2": "",
                        "postTown": "TEST",
                        "postal": "1111",
                        "stateProvinceCode": "CA"
                    }
                ],
                "telephones": [
                    {
                        "id": "Main_Phone_0",
                        "number": "1111111111"
                    }
                ],
                "emails": [
                    {
                        "id": "MAIN_EMAIL_0",
                        "type": "",
                        "email": ""
                    }
                ],
                "identityDocuments": [
                    {
                        "documentNumber": "111111111",
                        "hashedDocumentNumber": "",
                        "documentType": "SSN"
                    }
                ]
            }
        ],
        "application": {
            "applicants": [
                {
                    "contactId": "APPLICANT_CONTACT_ID_1",
                    "applicantType": "APPLICANT"
                }
            ]
        }
    }
}

I also saw this answer, but in my case the URL is not changing:

https://stackoverflow.com/questions/16130908/statuscode-404-reasonphrase-not-found-version-1-1

Per the Identity check company, I am supposed to include three headers in my JSON Request:

Accept:application/json
Content-Type:application/json
hmac-signature:<TheCalculatedHMACSignature>

any help will be greatly appreciated

来源:https://stackoverflow.com/questions/62272323/send-a-post-httprequest-to-a-identity-check-company

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!