FileHelperEngine engine = new FileHelperEngine(typeof(OrderCsvRow));
var writer = new StreamWriter(Response.OutputStream);
engine.WriteStream(writer, someOrders);
When I output the orders as a string it comes out fine. when I use Response.OutputSteam as in the code snipped the response it truncated towards the end - always at the same place.
How do I fix this?
Fixed...
engine.WriteStream(Response.Output, someOrders);
Had a similar issue here, so I'll put down the solution I found for anyone else who comes by and needs it.
Source: https://bytes.com/topic/asp-net/answers/484628-response-outputstream-truncates-xmltextwriter
After doing your write, make sure you also flush your stream writer before completing the request. Otherwise the missing data might end up being left behind and not actually appended to the OutputStream. :)
Related
I'm using FirebaseFirestoreSwift and Swift5.5 on iOS15+
I have this query:
#FirestoreQuery(
collectionPath: "/Users/" + Auth.auth().currentUser!.uid + "/Pages/"
) var pages2: [PageItem]
And I'm trying to get the following:
The structure is: /Users/{userId}/Pages/{pageId}/{key/value pairs}
I even confirmed from Firestore that the path was matching with its own.
This is from the console: /Users/JuzWOzAf54a7oFlOlb09dhAuOjI3/Pages/LZQAmbb18tYtz8ypkd8p
and this is what my string concatenation produces: /Users/JuzWOzAf54a7oFlOlb09dhAuOjI3/Pages/
So I should be getting the Page LZQAmbb18tYtz8ypkd8p and 3 others in the response, but thus far it is empty. Am I checking too early?
I am printing it like so:
.onAppear {
print(pages2)
}
On a view in the same file.
I don't even think it's a problem with printing it too soon, since it's meant to update in real-time.
But just incase it never showed since it was onAppear,and could have been received after, I added the following:
List {
ForEach(pages2) { page2 in
Text(page2.name)
}
}
And still, it receives nothing.
Not really sure what I'm doing wrong, I've researched and all I can find is a few resources, but they all seem to be doing the same thing, however, mine is simply not working, or I might be confused.
Any help is greatly appreciated, thank you!
Edit
This is the official SDK file whose methods I'm using:
https://github.com/firebase/firebase-ios-sdk/blob/master/Firestore%2FSwift%2FSource%2FPropertyWrapper%2FFirestoreQuery.swift
I am doing exactly as they propose.
I am trying to Put and Delete data through Almofire Library but facing issue regarding parameters. Params are missing, following are the error:
Response JSON data = {
data = "<null>";
issuccess = 0;
msg = "{'car_id': [ErrorDetail(string='This field is required.', code='required')], 'car_brand_id': [ErrorDetail(string='This field is required.', code='required')], 'last_oil_change': [ErrorDetail(string='Date has wrong format. Use one of these formats instead: YYYY-MM-DD.', code='invalid')]} with error { Custom error message. }";
}
I am using the following code:
let params : [String : String] = ["brand_model_id": String(car_model_id), "oil_brand_id": String(oil_brand_id), "car_mileage": edCurrentMilage.text!, "car_modelyear": edVehicleModelYear.text!, "last_oil_change": edLastOilChange.text!]
Alamofire.request(Constants.APIURL + Constants.APIPOSTCARDATA ,method:.put, parameters: params, encoding: JSONEncoding.default, headers: header).responseJSON { [self] response in
guard response.result.isSuccess,
let value = response.result.value else {
print("Error while fetching tags: \(String(describing: response.result.error))")
self.hideIndicator()
// self.btn_submit_outlet.isEnabled = true
// completion(nil)
return
}
print(value)
let json = JSON.init(value as! NSDictionary)
print(json)
let code = json["issuccess"].boolValue
if(code)
{
self.hideIndicator()
Commons.showAlert(title: "Alert", error: "Data has been added.", VC: self)
}
else
{
self.hideIndicator()
Commons.showAlert(title: String.localizedStringWithFormat(NSLocalizedString("Alert", comment: "")), error: String.localizedStringWithFormat(NSLocalizedString("Something went wrong.", comment: "")), VC: self)
}
}
Above mention code is used for the PUT call Please help. Thanks in advance.
It's not against you particularly, BUT, it's something that is lacking a lot in this kind of questions.
Usually, by reading output error, in our case the server response we might, and I insist on "might", find the solution. But it's not always the case, sometimes error message is too generic, or pointing to the wrong direction. Here, error is saying about missing "car_id" param, but according to you it's not needed, so it's misleading (if we believe your saying).
Another usually good hint, is saying that "It's working on Android", "It's working in Postman", "It's working with a cURL command".
Usually, when this happen, I'm asking myself:
Why the author doesn't show the Postman, Android code, cURL command that would allow people knowing both tools/languages/platforms to spot a difference that could be the mistake.
Let's be honest, that would be easier, no? You might have quickly the right solution/fix, no? It's better than trying to guess battling agains the server response, no?
Now...
You are using Alamofire AND Postman. What if I told you that might be enough for you?
Quick trivia:
Did you know that Postman can generate code for the request?
It can even generate Swift Code for your request using URLSession? It's not "beautiful", "swifty" Swift code, but it's enough to spot difference and find why it's working on Postman and not in your code.
It can also generate cURL command? If you don't know about cURL a quick explanation would be "command line tool to make web request with params etc in Terminal.app/Bash/Shell, ie: it's basic and usually known by a lot of developers, so even if you only speak JavaScript, Java, etc, it's often like a "common language"
How? Even when I say that in comments, people don't even try to search for it... Let's find it with your favorite Search Engine, which should lead you to this tutorial/blog post. And tadaaa!
Did you know that AlamoFire can print request as cURL equivalent? It's stated here.
So in your case, what about asking Alamofire and Postman to generate cURL command and compare?
Then, you might want to change the parameters of the request, or even the parameters of the method request(_:method:parameters:encoding:headers:).
Why I am saying this?
Because if you don't give enough informations, there will be a delay between someone asking for more info/details in comment and yourself responding to them. Also, different commenters will ask for different questions, since debugging is a skill and causes might be multiples, we might ask different things, and only one will be relevant in the end to your issue, but we can't guess which one until then.
Because spotting difference is easier and might attract quicker response.
Now that you know about POSTMAN and Alamofire and cURL, you might even find yourself the solution. Even quicker than making a question on SO! Be your own hero!
In the end, only an "attractive" question will have good answers, so give as much info as possible, don't hold them (parameters sent, equivalent android code, screenshot at least of the Postman, but know that you know about the cURL generation code). Of course, keep your private token etc, obfuscate them a little, but still, you might have watch enough TV shows/movies where holding info is bad for the main characters, why repeating that mistake here?
As the error message says: Date has wrong format. Use one of these formats instead: YYYY-MM-DD.
Please check "last_oil_change" field. The value is from edLastOilChange.text. Does edLastOilChange.text meet the required format?
I want to examine http requests in an extension for firefox. To begin figuring out how to do what I want to do I figured I'd just log everything and see what comes up:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);},
{urls: [/^.*$/]}
);
The domain is insignificant, and I know the regex works, verified in the console. When running this code I get no logging. When I take out the filter parameter I get every request:
webRequest.onResponseStarted.addListener(
(stuff) => {console.log(stuff);}
);
Cool, I'm probably doing something wrong, but I can't see what.
Another approach is to manually filter on my own:
var webRequest = Components.utils.import("resource://gre/modules/WebRequest.jsm", {});
var makeRequest = function(type) {
webRequest[type].addListener(
(stuff) => {
console.log(!stuff.url.match(/google.com.*/));
if(!stuff.url.match(/google.com.*/))
return;
console.log(type);
console.log(stuff);
}
);
}
makeRequest("onBeforeRequest");
makeRequest("onBeforeSentHeaders");
makeRequest("onSendHeaders");
makeRequest("onHeadersReceived");
makeRequest("onResponseStarted");
makeRequest("onCompleted");
With the console.log above the if, I can see the regex returning true when I want it to and the code making it past the if. When I remove the console.log above the if the if no longer gets executed.
My question is then, how do I get the filtering parameter to work or if that is indeed broken, how can I get the code past the if to be executed? Obviously, this is a fire hose, and to begin searching for a solution I will need to reduce the data.
Thanks
urls must be a string or an array of match patterns. Regular expressions are not supported.
WebRequest.jsm uses resource://gre/modules/MatchPattern.jsm. Someone might get confused with the util/match-pattern add-on sdk api, which does support regular expressions.
I am seeing a strange issue in Rails.
Request Body (request.body):
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][expiration_date]=20130513&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6415&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=GULF%20SHORES&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=8094%20BEACH%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6412&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=123%20ANY%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6411&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=104%20MERRIMONT%20ROAD&
renewals[][mailing_address][zip]=35023&
JSON Parsed Params (params[:renewals]): https://gist.github.com/t2/5566652
Notice in the JSON that the driver_1 information is missing on the last record. Not sure why this is. The data is in the request. Any known bug I am missing? Let me know if you need more info.
Unfortunately this is just how Rails parses JSON like this (where your [] is massively nested). I've come up against this before - http://guides.rubyonrails.org/form_helpers.html#combining-them gave some explanation.
From what I remember, if you can put in numeric keys rather than just [] (i.e. [1] for the first one, [2] for the second etc.) then it will work as you want it to.
So I figured it out. I needed to set the requestSerializationMIMEType to RKMIMETypeJSON.
How can I print a map from the OpenLayers? I want to add print button in my OpenLayers page =) I have MapFish extension for my geoserver, but don`t know how to make request to it. Any other ideas are welcome) Help please.
I had a similar problem using a reverse proxy, because I discovered the answer from info.json contais local ip reference instead of the public url
to solve brutally i replaced the ip referenze with the public url in the ajax request (see the following code. I hope it can be usefull for others...
this.capabilities.createURL = this.capabilities.createURL.replaceAll("192.168.0.0:8080", "mypublicurl");
this.capabilities.printURL= this.capabilities.printURL.replaceAll("192.168.0.0:8080", "mypublicurl");
Ext.Ajax.request({
url:this.capabilities.createURL,
jsonData:jsonData,
success:function(response){
response.responseText = response.responseText.replaceAll("192.168.0.0:8080", "mypublicurl");
window.open(Ext.decode(response.responseText).getURL);
}
});
The simplest way is to use GeoExt.PrintMapPanel (geoext example). And be sure to read GeoServer Printing Module.
UPD GET request example. You must modify url, "baseURL", "layers". If you specify an existing layer, this request must return pdf file.
http://demo.opengeo.org/geoserver/pdf/print.pdf?spec={"units":"degrees","srs":"EPSG:4326","layout":"A4","dpi":75,"mapTitle":"Printing Demo","comment":"This is a simple map printed from GeoExt.","layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":true,"type":"WMS","layers":["topp:tasmania_state_boundaries"],"format":"image/jpeg","styles":[""]}],"pages":[{"center":[146.56000000001,-41.56],"scale":8192000,"rotation":0}]}