我已经花了很多时间来解决问题。我正在调用第三方API,如
http://abc/app.aspx?deFleetLastName=MyName&Test123&deFleetFirstName=ààÃÅjeetaSisodiààÃÅ
在上面的网址中,我想允许&在像MyName和Test123这样的单词之间。 另外我想允许像ààÃÅjeetaSisodiààÃÅ
这样的西班牙语字符我使用下面的代码来允许西班牙语字符及其工作正常。
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;
}
当用户输入&焦炭。 允许&我们可以使用HttpUtility.UrlEncode,但我不想使用HttpUtility.Urlencode
请建议我如何允许&以上API调用中的西班牙语字符
答案 0 :(得分:3)
您可以使用%26替换&查询变量中的符号。它的数量相同(有点像%20相当于一个空格)。解析变量并替换&使用上面的代码,你应该设置。
例如,您可以编写与MyName%26Test123
MyName&Test123
请参阅http://www.degraeve.com/reference/urlencoding.php作为用于替换字符的不同代码的参考
<强>更新强>
根据我在API构造中可以看到的内容,您可以非常轻松地对其进行排序。您的所有数据都存储在一个类中,因此请使用以下
遍历每个属性public void ParseAmpersand()
{
foreach (PropertyInfo pi in this.GetType().GetProperties())
{
if (pi.PropertyType == typeof(string)
{
((string)pi.GetValue(this)).Replace("&", "%26");
}
}
}
这将循环遍历该对象中string
类型的所有属性,并替换&amp;使用%26代码。您需要做的就是将其放入您已创建的类(SecCardReq
)中,并在构建API字符串之前调用它。