Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow & in between a word in url with Spanish characters without url encoding

I Had sped lots of time to resolve a issue. I am Calling a 3rd party API like

http://abc/app.aspx?deFleetLastName=MyName&Test123&deFleetFirstName=ààÃÅjeetaSisodiààÃÅ

In above url I want to allow & between a word like MyName&Test123. Also I want to allow Spanish characters like ààÃÅjeetaSisodiààÃÅ

I am using below code to allow Spanish characters and its working fine.

AuthRequest = "&deTCIVRAccountNumber=" + SecCardReq.AdminNumber;
                AuthRequest += "&deCISSTitle=" + SecCardReq.Title;
                AuthRequest += "&deTCIVRCardHolderIdentFirstName=" + SecCardReq.FirstName;
                AuthRequest += "&deTCIVRCardHolderIdentMiddleName=" + SecCardReq.MiddleName;
                AuthRequest += "&deTCIVRCardHolderIdentLastName=" + SecCardReq.LastName;
                AuthRequest += "&deCISSSecLastName=" + SecCardReq.SecLastName;
                AuthRequest += "&deCISSNameOnCard=" + SecCardReq.NameOnCard;
                AuthRequest += "&deTCIVRCardHolderIdentAddressLine1=" + SecCardReq.AddressLine1;
                AuthRequest += "&deTCIVRCardHolderIdentAddressLine2=" + SecCardReq.AddressLine2;
                AuthRequest += "&deTCIVRCardRegistrationCity=" + SecCardReq.City;
                AuthRequest += "&deTCIVRCardHolderIdentificationStateProvince=" + SecCardReq.State;
                AuthRequest += "&deTCIVRCardRegistrationPostalCode=" + SecCardReq.PostalCode;
                AuthRequest += "&deTCIVRCardRegistrationCountry=" + SecCardReq.Country;
                AuthRequest += "&deTCIVRCardRegistrationEmail=" + SecCardReq.Email;
                AuthRequest += "&deCISSEmail2=" + SecCardReq.Email2;
                AuthRequest += "&deTCIVRCardHolderIdentDOB=" + SecCardReq.DOB;
                AuthRequest += "&deCISSMotherMaidenName=" + SecCardReq.MotherMaidenName;
                AuthRequest += "&deTCIVRCardHolderIdentificationIdCode=" + SecCardReq.IdType;
                AuthRequest += "&deCIAOtherIDDescription=" + SecCardReq.IDDescription;
                AuthRequest += "&deTCIVRCardHolderIdentificationIdNumber=" + SecCardReq.IdNumber;
                AuthRequest += "&deCIAIDIssueDate=" + Convert.ToString(SecCardReq.IDIssueDate);
                AuthRequest += "&deCIAIDExpirationDate=" + Convert.ToString(SecCardReq.IDExpirationDate);

                AuthRequest += "&deCIASIssuedBy=" + SecCardReq.IDIssuedBy;
                AuthRequest += "&deCIAIDIssueState=" + SecCardReq.IDIssueState;
                AuthRequest += "&deSecondaryCardTypeForAPI=" + SecCardReq.SecondaryCardTypeForAPI;
                AuthRequest += "&deCIASHomePhoneCCode=" + SecCardReq.HomePhoneCountryCode;
                AuthRequest += "&deTCIVRCardRegistrationPhone=" + SecCardReq.HomePhoneNumber;
                AuthRequest += "&deCIASOfficePhoneCCode=" + SecCardReq.WorkPhoneCountryCode;
                AuthRequest += "&deCISSWorkPhoneNumber=" + SecCardReq.WorkPhoneNumber;
                AuthRequest += "&deCIASOfficePhoneExt=" + SecCardReq.WorkPhoneExt;
                AuthRequest += "&deMobilePhCCode=" + SecCardReq.MobilePhoneNumberCCode;
                AuthRequest += "&deCISSMobilePhoneNumber=" + SecCardReq.MobilePhoneNumber;
                AuthRequest += "&deFaxNumberCCode=" + SecCardReq.HomeFaxNumberCCode;
                AuthRequest += "&deCISSHomeFaxNumber=" + SecCardReq.HomeFaxNumber;
                AuthRequest += "&deWorkFaxNumberCCode=" + SecCardReq.WorkFaxNumberCCode;
                AuthRequest += "&deCISSWorkFaxNumber=" + SecCardReq.WorkFaxNumber;
                AuthRequest += "&deCISSLanguageIndicator=" + SecCardReq.LanguageIndicator;
                AuthRequest += "&deSecondaryCardPinAPI=" + SecCardReq.SecondaryCardPin;
                AuthRequest += "&deSecondaryCardDealerNumberForAPI=" + SecCardReq.SecondaryCardDealerNumber;
                AuthRequest += "&deIVREmbossingHotStamp=" + SecCardReq.EmbossingHotStamp;
                AuthRequest += "&deSecondaryCardPrivacy=" + SecCardReq.SecondaryCardPrivacy;
                AuthRequest += "&dePPCIPNumber=" + SecCardReq.PPCIPNumber;
                AuthRequest += "&deIVREmbossingLine4=" + SecCardReq.EmbossingLine4;
                AuthRequest += "&dePPCIPType=" + SecCardReq.PPCIPType;
                AuthRequest += "&dePDDeliveryMechanism=" + SecCardReq.DeliveryMechanism;
                AuthRequest += "&dePPCIPStatus=" + SecCardReq.PPCIPStatus;
                AuthRequest += "&deSecondaryCardExpOptForAPI=" + (SecCardReq.SecondaryCardExpOpt != null ? SecCardReq.SecondaryCardExpOpt : "");
                AuthRequest += "&deSecondaryVCExpAfrTxnEntryAPI=" + SecCardReq.SecondaryVCExpAfrTxnEntry ?? "";
                AuthRequest += "&deSecondaryVCExprAfrDaysEntryAPI=" + SecCardReq.SecondaryVCExprAfrDaysEntry ?? "";
                AuthRequest += "&deSecondaryVCExprAfrDaysEntryDuration=" + SecCardReq.SecondaryVCExprAfrDaysEntryDuration ?? "";
                AuthRequest += "&deSecondaryVCExpOnDate=" + (SecCardReq.SecondaryVCExpOnDate != null ? SecCardReq.SecondaryVCExpOnDate : "");
                AuthRequest += "&deSecondaryVirtualCardLimit=" + SecCardReq.SecondaryVirtualCardLimit;
                AuthRequest += "&deSecondaryVirtualCardResetAllowedForAPI=" + "0"; // As per new changes in SCP
                AuthRequest += "&deCardValidFromDateAPI=" + SecCardReq.StartDate; // As per new changes in SCP
                AuthRequest += "&deCardValidTillDateAPI=" + SecCardReq.StopDate; // As per new changes in SCP
                AuthRequest += "&deBookingRefNumber=" + SecCardReq.BookingRefNumber; // As per new changes in SCP
                AuthRequest += "&dePPSSN=" + SecCardReq.DecryptedSSN;
                AuthRequest += "&deIVRSource=" + PortalCommon.PlateFormName;
                AuthRequest += "&deMakerCheckerJobID=" + SecCardReq.jobID;
                AuthRequest += "&deMakerCheckerFlag=" + SecCardReq.makerCheckerFlag;

                AuthRequest += "&deExistingCustomerId=" + SecCardReq.CustomerId;
                AuthRequest += "&deBankingCustomerIdAPI=" + SecCardReq.BankingCustomerId;

                //IDS CIBANCO CHANGES
                AuthRequest += "&dePoBCountry=" + SecCardReq.POBCountry;
                AuthRequest += "&dePoBState=" + SecCardReq.POBStateProvince;
                AuthRequest += "&dePoBCity=" + SecCardReq.POBCity;
                AuthRequest += "&deNationality=" + SecCardReq.Nationality;
                AuthRequest += "&deSACCode=" + SecCardReq.SACActivationCode;
                AuthRequest += "&deCHCustomerIdDetailMsg=" + SecCardReq.IDDetails;

                HttpRequestMsg = "User=" + (Convert.ToString(UserLogin));
                HttpRequestMsg += "&Password=" + HttpUtility.UrlEncode(Convert.ToString(UserPassword));
                HttpRequestMsg += "&Application=appCardinal";
                HttpRequestMsg += "&dbbServiceName=svcIVRSecondaryCard";
                HttpRequestMsg += "&dbbSystemExtLogin=1";
                HttpRequestMsg += "&deDBBServiceApiLevel=1.2";


 HttpRequestMsg += AuthRequest;
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(BaseUrl);
                httpRequest.Method = "POST"; httpRequest.Headers.Add("X-Forwarded-For", objLoginUserInfo.HostIp); httpRequest.Headers.Add("Authorization", AddAuthorizationHeader());
                httpRequest.ContentType = "application/x-www-form-urlencoded";
                httpRequest.CookieContainer = new CookieContainer();

                string sOutput = string.Empty;
                sOutput = CommonBLL.GetDBBIDServiceResponse(httpRequest, HttpRequestMsg);



   public static string GetDBBIDServiceResponse(HttpWebRequest httpRequest, string httpRequestMsg)
    {
        string responseString = string.Empty;
        try
        {
            Utilities.APITraceEnable(httpRequestMsg);
            byte[] byteArray = Encoding.GetEncoding(1252).GetBytes(httpRequestMsg);
            httpRequest.ContentLength = byteArray.Length;
            Stream newStream = httpRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();
            HttpWebResponse getResponse = (HttpWebResponse)httpRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                responseString = sr.ReadToEnd();
            }
        }
        catch (Exception ex)
        {
            CreateLogFile.CreateActivityLog("CommonBLL GetEncodingWindows1252 Exception =============== " + ex.Message, ex.StackTrace);
        }
        return responseString;
    }

Problem occurs when user enter & char. To allow & we can use HttpUtility.UrlEncode , but I don't want to use HttpUtility.Urlencode

Please suggest me how can allow & and Spanish characters in above API calling

like image 452
Jaihind Avatar asked Oct 18 '22 17:10

Jaihind


1 Answers

You can use %26 to replace the & symbol within your query variables. It counts as the same (a bit like how %20 is the equivalent to a space). Parse your variables and replace the & with the above code and you should be set.

For example, you could write MyName%26Test123 which would be the same as MyName&Test123

See http://www.degraeve.com/reference/urlencoding.php as a reference to the different codes used to replace characters

Update

Based on what I can see from your API construction, you can sort this out pretty easily. All your data is stored in a single class, so cycle through each property using the following

public void ParseAmpersand()
{
    foreach (PropertyInfo pi in this.GetType().GetProperties())
    {
        if (pi.PropertyType == typeof(string)
        {
            ((string)pi.GetValue(this)).Replace("&", "%26");
        }
    }               
}

This will cycle through all properties in that object that are of type string and replace the & with the %26 code. All you need to do is place this into the class you already created (SecCardReq) and call it before you build your API string.

like image 69
Takarii Avatar answered Oct 20 '22 23:10

Takarii