0

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

Anjali
  • 2,540
  • 7
  • 37
  • 77
  • Let me know if anyone needs any additional details. Please don't just down vote this question. I tried to put as many details as I can. – Anjali Jun 08 '20 at 22:58
  • 1
    You get a 404 when your URL is wrong. You need to check and make sure you're accessing the right URL. – HazardousGlitch Jun 08 '20 at 23:24
  • I am using the same URL in SOAP UI and it works fine and I get the response back. – Anjali Jun 08 '20 at 23:40
  • I'm guessing the URL isn't a secret. If it isn't, please edit your question with it. – HazardousGlitch Jun 08 '20 at 23:47
  • I removed this line : HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "relativeAddress"); and put this instead HttpRequestMessage request = new HttpRequestMessage(); request.Method = HttpMethod.Post; and I am getting 200 ok response now. – Anjali Jun 08 '20 at 23:50
  • 1
    I guess this relative address was wrong and it was the URL after all. – Anjali Jun 08 '20 at 23:50

0 Answers0