In HTTP request we may get data from body or query-string. In this topic we will assume JSON is body format.
In JSON we are able to distinguish integer string and boolean parameters.
{
"tata": "test",
"titi": 123,
"toto": true
}
But is there a way in query-string to distinguish integer string and boolean parameters ?
https://example.com/path/to/page?titi=123&toto=true
// titi is integer or string ?
// toto is boolean or string ?
There is no way to distinguish from the query string because it's a string, only from a json
Related
my query paramS is x-goog-one=something&x-goog-two=something_else&.......
i have this as a string format its like a very long query param String
do we have anything like #requestParams to process the queryParamS in one param insted of:
#Component
#FeignClient(name = "fileUpload", url = FileUploadSao.GMS)
public interface FileUploadSao {
#PutMapping(value = "/{fileName}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> uploadFile(#PathVariable("fileName") String filename,
#RequestParam("X-Goog-Algorithm") String xGoogAlgorithm,
#RequestParam("X-Goog-Credential") String credentials,
#RequestParam("X-Goog-Date") String date,
#RequestParam("X-Goog-Expires") String expires,
#RequestParam("X-Goog-SignedHeaders") String signedHeaders,
byte[] imageBinary);
}
Request params hangling in spring mvc,openFeign , I want to process all my query params in one String referense
I have a database schema that I do not control (it's a sqlite3 file exported from a desktop application that I need to interoperate with), that contains UUIDs for some of the columns. I'm using sqlite-net-pcl in a Xamarin.Forms app, and I cannot work out how to successfully read these columns. Here's what I've tried:
using the sqlite3 command line, I've confirmed that the schema has type uuid for the relevant column, and using select count(distinct uuidcolumn) from mytable; I've confirmed that there are values for each row. (The column is nullable which is relevant for the code snippet below but in practice all the rows have non-null values)
I have this model object:
namespace brahms.Model
{
[Table("mytable")]
public class MyTable
{
[Column("uuidcolumn")]
public Guid UUIDColumn { get; }
[PrimaryKey, AutoIncrement, NotNull]
[Column("recordid")]
public int RecordID { get; set; }
}
}
if I fetch an object using database.Query<MyTable>() queries, UUIDColumn is always equal to Guid.Empty.
I tried switching the type in the class definition to Byte[]; it's always null.
I tried switching the type in the class definition to string; it's always null.
Same applies to the UInt16[] type (the GUID might be stored as a blob of 16-bit words, so I tried that type too)
How can I read the values in uuid-typed columns using sqlite-net-pcl?
I gave up on using the ORM features in sqlite-net-pcl and used this query:
db.executeScalar<byte[]>('select hex(uuidcolumn) from mytable where recordid=1');
What I get back is 72 bytes, which appear to represent the 36 ASCII characters in a string representation of a Guid (every so often one of the characters is 2D, which is - in the ASCII set). So I think that the backing store is a blob but one that's storing the text representation of the Guid, which is weird, but I'll be able to reconstruct the Guid from here.
Using this answer and getting that blob as a string, I ended up with this implementation:
public Guid GetUUIDColumn()
{
string dbRep = _database.ExecuteScalar<string>("select hex(uuidcolumn) from mytable where recordid = ?", RecordID);
if (dbRep == null || dbRep == string.Empty) return Guid.Empty;
var bytes = new byte[dbRep.Length / 2];
// each pair of bytes represents the ASCII code (in hexadecimal) for a character in the string representation of a Guid.
for (var i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(dbRep.Substring(i * 2, 2), 16);
}
string asString = Encoding.ASCII.GetString(bytes);
return new Guid(asString);
}
I am trying to figure out a way to stop Retrofit from encoding the email address that I pass to make a POST request. Here is my POST interface
#POST("/security/oauth/token")
#FormUrlEncoded
void getAccessToken(#Field("client_id") String clientId,
#Field("client_secret") String clientSecret,
#Field("username") String username,
#Field("password") String password,
#Field("grant_type") String grantType, Callback<AccessToken> cb);
When I make the request, Retrofit sends these fields as
client_id=test&client_secret=cajcckkcaaa&username=androidtest12%40gmail.com&password=Password23&grant_type=password
The culprit here is the email address, which is being changed from androidtest12#gmail.com to androidtest12%40gmail.com causing server error.
Thanks in advance for help.
You need to set encodeValue = false for your username field for this to work because it is being encoded. They have this documented over at the Retrofit Javadoc. An example is below using your data.
#POST("/security/oauth/token")
#FormUrlEncoded
void getAccessToken(#Field("client_id") String clientId,
#Field("client_secret") String clientSecret,
#Field(encodeValue = false, value = "username") String username,
#Field("password") String password,
#Field("grant_type") String grantType, Callback<AccessToken> cb);
For Retrofit 2 you should use #Query with encoded = true like this:
public interface ValidateEmailApi {
#GET("/api/email")
Call<Void> validateEmail(#Query(encoded = true, value = "email") #NonNull String email);
}
So in my web service i get the data from textboxes search it in database and create letter objects.Then add those objects to a list.my question is how do i return the list to my web page and create divs. for example if service finds 5 letters how i do i return them and create 5 different divs with their data.Thanks in advance
public Letter(string lid, string companyname, string personname, string email, string fax, string phone, string industryname, string teamname, string sender, string statusname, string description, string date)
{
LID = lid;
CompanyName = companyname;
PersonName = personname;
Email = email;
Fax = fax;
Phone = phone;
IndustryName = industryname;
TeamName = teamname;
Sender = sender;
StatusName = statusname;
Description = description;
Date = date;
}
You just need to decorate your web services with ScriptService attribute and it will return response in raw json format. For more info check it out here and you also want to check out this.
Once you get Json response, you can do something like this to render the output as per your requirement. It's not exactly what you're looking for but it will give you an idea how to proceed further.
In .net 3.5 you can create json by using the System.Web.Script.Serialization.JavaScriptSerializer otherwise you have to do it manually or by a 3rd party component.
I'm implementing a custom control and in this control I need to write a bunch of links to the current page, each one with a different query parameter. I need to keep existing query string intact, and add (or modify the value of ) an extra query item (eg. "page"):
"Default.aspx?page=1"
"Default.aspx?page=2"
"Default.aspx?someother=true&page=2"
etc.
Is there a simple helper method that I can use in the Render method ... uhmm ... like:
Page.ClientScript.SomeURLBuilderMethodHere(this,"page","1");
Page.ClientScript.SomeURLBuilderMethodHere(this,"page","2");
That will take care of generating a correct URL, maintain existing query string items and not create duplicates eg. page=1&page=2&page=3?
Rolling up my own seems like such an unappealing task.
I'm afraid I don't know of any built-in method for this, we use this method that takes the querystring and sets parameters
/// <summary>
/// Set a parameter value in a query string. If the parameter is not found in the passed in query string,
/// it is added to the end of the query string
/// </summary>
/// <param name="queryString">The query string that is to be manipulated</param>
/// <param name="paramName">The name of the parameter</param>
/// <param name="paramValue">The value that the parameter is to be set to</param>
/// <returns>The query string with the parameter set to the new value.</returns>
public static string SetParameter(string queryString, string paramName, object paramValue)
{
//create the regex
//match paramname=*
//string regex = String.Format(#"{0}=[^&]*", paramName);
string regex = #"([&?]{0,1})" + String.Format(#"({0}=[^&]*)", paramName);
RegexOptions options = RegexOptions.RightToLeft;
// Querystring has parameters...
if (Regex.IsMatch(queryString, regex, options))
{
queryString = Regex.Replace(queryString, regex, String.Format("$1{0}={1}", paramName, paramValue));
}
else
{
// If no querystring just return the Parameter Key/Value
if (queryString == String.Empty)
{
return String.Format("{0}={1}", paramName, paramValue);
}
else
{
// Append the new parameter key/value to the end of querystring
queryString = String.Format("{0}&{1}={2}", queryString, paramName, paramValue);
}
}
return queryString;
}
Obviously you could use the QueryString NameValueCollection property of the URI object to make looking up the values easier, but we wanted to be able to parse any querystring.
Oh and we have this method too that allows you to put in a whole URL string without having to get the querystring out of it
public static string SetParameterInUrl(string url, string paramName, object paramValue)
{
int queryStringIndex = url.IndexOf("?");
string path;
string queryString;
if (queryStringIndex >= 0 && !url.EndsWith("?"))
{
path = url.Substring(0, queryStringIndex);
queryString = url.Substring(queryStringIndex + 1);
}
else
{
path = url;
queryString = string.Empty;
}
return path + "?" + SetParameter(queryString, paramName, paramValue);
}